使用范围:
统一配置中心,保存在etcd集群中,更新不是很及时
configmap和secret区别
- kubectl describe 对应信息,configmap显示键值 secret只显示键不显示值
- kubectl get 对应信息,configmap明文显示 secret base64位加密显示
configMap作为配置文件使用
创建文件类型 kubectl create configmap my-config --from-file=key1=/path/to/bar/file1.txt 使用 在pod中定义使用 apiVersion: v1 kind: Pod metadata: name: configmap-pod spec: containers: - name: test image: busybox volumeMounts: - name: config-vol mountPath: /etc/config volumes: - name: config-vol configMap: name: my-config 然后文件my-config就挂载在pod /etc/config目录下 key value的configmap kubectl create configmap my-config key=value
注意
- volumeMounts下面如果有多条,mountPath不能一致
- 如果没有配置subPath,则configMap默认会将挂载目录东西全部覆盖,如果只是要挂载一个文件到一个目录,则需要加上subPath,pod挂载范例如下。
volumeMounts: - name: config-vol mountPath: /etc/config.conf subPath: config.conf #如果加上subPath 写上文件名,代表挂载的是文件,不会将原目录覆盖,但是如果有源文件会被覆盖
评论区