kubernetes-ConfigMap
ConfigMap简介
ConfigMap API资源用来保存key-value pair配置数据,这个数据可以在pods里使用,或者被用来为像controller一样的系统组件存储配置数据。虽然ConfigMap跟Secrets类似,但是ConfigMap更方便的处理不含敏感信息的字符串。 注意:ConfigMaps不是属性配置文件的替代品。ConfigMaps只是作为多个properties文件的引用。你可以把它理解为Linux系统中的/etc目录,专门用来存储配置文件的目录
ConfigMap创建
创建ConfigMap的方式有4种:
使用字面值创建
使用文件创建
使用目录创建
编写configmap的yaml文件创建
使用字面值创建
[root@server2 ~]# kubectl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2
configmap/my-config created
[root@server2 ~]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 6d16h
my-config 2 6s
[root@server2 ~]# kubectl describe cm my-config
Name: my-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
key1:
----
config1
key2:
----
config2
Events: <none>
[root@server2 configmap]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 6d18h
my-config 2 130m
使用文件创建
[root@server2 ~]# kubectl create configmap my-config-2 --from-file=/etc/resolv.conf
configmap/my-config-2 created
[root@server2 ~]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 6d16h
my-config 2 84s
my-config-2 1 5s
[root@server2 ~]# kubectl describe cm my-config-2
Name: my-config-2
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
resolv.conf:
----
# Generated by NetworkManager
nameserver 114.114.114.114
Events: <none>
[root@server2 configmap]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 6d18h
my-config 2 130m
my-config-2 1 129m
使用目录创建
[root@server2 ~]# mkdir configmap
[root@server2 ~]# cd configmap/
[root@server2 configmap]# mkdir test
[root@server2 configmap]# cp /etc/passwd test/
[root@server2 configmap]# cp /etc/fstab test/
[root@server2 configmap]# ls test/
fstab passwd
[root@server2 configmap]# kubectl create configmap my-config-3 --from-file=test
configmap/my-config-3 created
[root@server2 configmap]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 6d16h
my-config 2 3m45s
my-config-2 1 2m26s
my-config-3 2 7s
[root@server2 configmap]# kubectl describe cm my-config-3
Name: my-config-3
Namespace: default
Labels: <none>
Annotations: <none>
Data
==<