效果就跟指定整个目录是一样的 [[emailprotected] dir]# kubectl create config
标签:
一、configmap1.1、configmap简介ConfigMap 成果在 Kubernetes1.2 版本中引入,许多应用措施会从配置文件、命令行参数或环境变量中读取配置信息。ConfigMap API 给我们供给了向容器中注入配置信息的机制,ConfigMap 可以被用来生存单个属性,也可以用来生存整个配置文件或者 JSON 二进制东西
1.2、ConfigMap 的创建1.2.1、使用目录创建[[email protected] dir]# ls game.propertie ui.propertie [[email protected] dir]# cat game.propertie enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 [[email protected] dir]# cat ui.propertie color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice #从目录创建configmap #—from-file指定在目录下的所有文件城市被用在 ConfigMap 里面创建一个键值对,键的名字就是文件名,值就是文件的内容 [[email protected] dir]# kubectl create configmap game-config --from-file=./ configmap/game-config created [[email protected] dir]# kubectl get configmap NAME DATA AGE game-config 2 14s [[email protected] dir]# kubectl get cm NAME DATA AGE game-config 2 18s [[email protected] dir]# kubectl get cm game-config -o yaml apiVersion: v1 data: game.propertie: | enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 ui.propertie: | color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice kind: ConfigMap metadata: creationTimestamp: "2020-02-04T05:13:30Z" name: game-config namespace: default resourceVersion: "144337" selfLink: /api/v1/namespaces/default/configmaps/game-config uid: 0fc2df14-d5ee-4092-ba9e-cc733e8d5893 [[email protected] dir]# kubectl describe cm game-config Name: game-config Namespace: default Labels: <none> Annotations: <none> Data ==== game.propertie: ---- enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 ui.propertie: ---- color.good=purple color.bad=yellow allow.textmode=true how.nice.to.look=fairlyNice Events: <none>1.2.2、使用文件创建只要指定为一个文件就可以从单个文件中创建 ConfigMap
—from-file这个参数可以使用多次,你可以使用两次分袂指定上个实例中的那两个配置文件,效果就跟指定整个目录是一样的
[[email protected] dir]# kubectl create configmap game-config-2 --from-file=./game.propertie configmap/game-config-2 created [[email protected] dir]# kubectl get cm game-config-2 NAME DATA AGE game-config-2 1 16s [[email protected] dir]# kubectl get cm game-config-2 -o yaml apiVersion: v1 data: game.propertie: | enemies=aliens lives=3 enemies.cheat=true enemies.cheat.level=noGoodRotten secret.code.passphrase=UUDDLRLRBABAS secret.code.allowed=true secret.code.lives=30 kind: ConfigMap metadata: creationTimestamp: "2020-02-04T05:25:13Z" name: game-config-2 namespace: default resourceVersion: "145449" selfLink: /api/v1/namespaces/default/configmaps/game-config-2 uid: df209574-202d-4564-95ca-19532abd6b7b1.2.3、使用字面值创建使用文字值创建,操作—from-literal参数通报配置信息,该参数可以使用多次
[[email protected] dir]# kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm configmap/special-config created [[email protected] dir]# kubectl get cm special-config -o yaml apiVersion: v1 data: special.how: very special.type: charm kind: ConfigMap metadata: creationTimestamp: "2020-02-04T05:27:43Z" name: special-config namespace: default resourceVersion: "145688" selfLink: /api/v1/namespaces/default/configmaps/special-config uid: 72b58e0e-f055-43dd-aa04-a7b2e9007227kubernetes(五)--存储之configmap/secret/volume/Persistent Volume
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/30569.html