|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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了