美文网首页Kubernetesk8s那点事儿k8s入门
K8S configMap 作为统一配置文件中心

K8S configMap 作为统一配置文件中心

作者: lyy910203 | 来源:发表于2019-06-12 09:44 被阅读4次
timg (2).jpg

使用范围:

统一配置中心,保存在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  写上文件名,代表挂载的是文件,不会将原目录覆盖,但是如果有源文件会被覆盖

相关文章

网友评论

    本文标题:K8S configMap 作为统一配置文件中心

    本文链接:https://www.haomeiwen.com/subject/xjqkfctx.html