题目要求
- 更新在 namespace default 中的 Service nginxsvc 来暴露端口 9090 。
- 在 namespace default 中创建一个名为 haproxy-config 并存储着的**/ckad/ambassador/haproxy.cfg** 的内容的 ConfigMap。
- 更新在 namespace default 中名为 poller 的 Pod:
- 首先,添加一个使用 haproxy:lts 镜像、暴露端口 80 并名为 ambassador-container 的 ambassador 容器(sidecar模式)。
- 最后,ConfigMap haproxy-config 要挂载到 ambassador 容器 ambassador-container 的**/usr/local/etc/haproxy/**目录。
参考
https://kubernetes.io/zh-cn/docs/concepts/configuration/configmap/
https://kubernetes.io/docs/reference/kubectl/generated/kubectl_create/kubectl_create_configmap/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| apiVersion: v1 kind: Pod metadata: name: mypod spec: containers: - name: mypod image: redis volumeMounts: - name: foo mountPath: "/etc/foo" readOnly: true volumes: - name: foo configMap: name: myconfigmap
|
解答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| kubectl -n default get svc kubectl -n default edit svc nginxsvc apiVersion: v1 kind: Service metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"nginxsvc","namespace":"default"},"spec":{"ports":[{"port":80,"protocol":"TCP","targetPort":80}],"selector":{"app":"nginxsvc"}}} creationTimestamp: "2023-05-24T13:45:01Z" name: nginxsvc namespace: default resourceVersion: "17051" uid: cd4c38bd-e282-414f-a4cb-9fe3a5ccd0c5 spec: clusterIP: 10.111.178.212 clusterIPs: - 10.111.178.212 internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - port: 9090 protocol: TCP targetPort: 80 selector: app: nginxsvc sessionAffinity: None type: ClusterIP status: loadBalancer: {}
kubectl -n default get svc nginxsvc -owide
kubectl create configmap **haproxy-config** --from-file=**/ckad/ambassador/haproxy.cfg
kubectl -n default get pod poller -oyaml > poller.yaml cp poller.yaml poller_bak.yaml
kubectl delete -f poller.yaml
vim poller.yaml
... - name: **ambassador-container** image: **haproxy:lts** volumeMounts: - name: foo mountPath: "**/usr/local/etc/haproxy/**" readOnly: true volumes: - name: foo configMap: name: **haproxy-config ...
kubectl apply -f poller.yaml
curl 10.111.178.212:9090**
|