configmap官网
ConfigMap是一种 API 对象,使用时, Pods 可以将其用作环境变量、命令行参数或者存储卷中的配置文件。ConfigMap将配置和Pod解耦,更易于配置文件的更改和管理。ConfigMap 并不提供保密或者加密功能。 如果你想存储的数据是机密的,请使用Secret。
参考资料
ConfigMap的生命周期以及使用方式,
# configmap 配置文件
apiVersion: v1
kind: ConfigMap
metadata:name: k8s-config
data:key1: hellokey2: k8s
》》volume挂载
# 在volumes配置中通过对configMap的name进行匹配,然后根据key字段取出对应的配置,并绑定到对印的path上。
volumes:- name: "test-log-config" #创建volume的名称 configMap: name: "test-conf" #引用configMap卷items:- key: "log4j2.xml" #根据key获取configMap指定的配置path: "log4j2.xml"- name: "test-init-config"configMap:name: "test-conf"items:- key: "init-config.json" #根据key获取configMap指定的配置path: "init-config.json"- name: "test-application"configMap:name: "test-conf"items:- key: "test-application-remote.properties" #根据key获取configMap指定的配置path: "application-remote.properties"# 接下来就是使用volumeMounts属性对volume进行mount,当Pod实例化以后会将配置文件生成到具体路径供业务系统使用:volumeMounts:- name: "test-application"mountPath: "/home/test/app/config/application-remote.properties"subPath: "application-remote.properties"- name: "test-init-config"mountPath: "/home/test/app/config/init-config.json"subPath: "init-config.json"- name: "test-log-config"mountPath: "/home/test/app/config/log4j2.xml"subPath: "log4j2.xml"