|NO.Z.00177|——————————|CloudNative|——|KuberNetes&配置管理.V08|——|configmap.v08|将configmap数据添加到卷中的特定路径|
一、将configmap数据添加到卷中的特定路径
### --- 将configmap数据添加到卷中的特定路径
~~~ # 修改pod-configmap.yaml配置文件
~~~ 使用该path字段可以为特定的ConfigMap项目指定所需的文件路径。
~~~ 在这种情况下,该SPECIAL_LEVEL项目将安装在的config-volume卷中/etc/config/keys
~~~ 会自动更新配置文件,但是你的程序需要由reload机制,在程序reload的时候,
~~~ 会重新读取这个文件,会更新配置文件,
[root@k8s-master01 configmap]# vim pod-configmap-volume-specific-key.yaml
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh","-c","cat /etc/config/keys" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: special-config
items:
- key: SPECIAL_LEVEL
path: keys
restartPolicy: Never
### --- 重新创建pod
~~~ 当pod运行时,该命令将cat /etc/config/keys产生以下输出:
~~~ # 注意:与以前一样,该/etc/config/目录中的所有先前文件都将被删除。
[root@k8s-master01 configmap]# kubectl create -f https://kubernetes.io/examples/pods/pod-configmap-volume-specific-key.yaml
[root@k8s-master01 configmap]# very
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
浙公网安备 33010602011771号