题目要求
- 在 namespace default 中创建一个名为 some-config 并存储着以下键值对的 Configmap: key3:value4
- 在 namespace default 中创建一个名为 nginx-configmap 的 Pod 。用 nginx:stable 的镜像来指定一个容器。用存储在Configmap some-config 中的数据来填充卷 并将其安装在路径 /some/path
参考
https://kubernetes.io/zh-cn/docs/concepts/configuration/configmap/
解答
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
| kubectl create configmap some-config --from-literal=key3=value4 --dry-run=client -o yaml > configmap.yaml cat configmap.yaml apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: nginx-configmap name: nginx-configmap spec: containers: - image: nginx:stable name: nginx-configmap resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {}
kubectl run nginx-configmap --image=nginx:stable --dry-run=client -o yaml > nginx-configmap.yaml
vim nginx-configmap.yaml apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: nginx-configmap name: nginx-configmap spec: containers: - image: nginx:stable name: nginx-configmap volumeMounts: - name: foo mountPath: "/some/path" readOnly: true volumes: - name: foo configMap: name: some-config dnsPolicy: ClusterFirst restartPolicy: Always status: {}
kubectl apply -f nginx-configmap.yaml
kubectl exec -it nginx-configmap -- cat /some/path/key3
|