概念:ConfigMap是一种比较特殊的存储卷、它主要的作用是用来存储配置信息的
其模板如下:
1、创建配置卷的yaml文件:vim configmap.yaml
-------------------------------------------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap
namespace: dev
data: #数据由键值对组成
info: #key
username:admin #volume
password:123456
-------------------------------------
2、创建:kubectl create -f configmap.yaml
3、查看:kubectl describe cm -ndev
--------------------------------------------------------------
Name: configmap
Namespace: dev
Labels: <none>
Annotations: <none>
Data
====
info: #键
----
username:admin password:123456 #值
Events: <none>
----------------------------------------------------------------------
4、将这个配置信息configMap挂载到pod里去:
·创建pod.yaml:vim pod-configmap.yaml
------------------------------------------------------------------------------------------
apiVersion: v1
kind: Pod
metadata:
name: pod-configmap
namespace: dev
spec:
containers:
- name: nginx
image: nginx:1.17.1
volumeMounts:
- name: config #要挂载到哪一个卷类型的名字、要与本机挂载的卷名要一致
mountPath: /configmap/config #将容器中的/configmap/config 目录挂载到本机的 configMap 配置卷上(进入容器中会有这个目录)
volumes: #引用configmap
- name: config
configMap: #卷类型
name: configmap #注意这个名字要和上面创建的configMap的名字要一致、表示使用以这个名字命名的卷
-------------------------------------------------------------------------------------------------------------
5、创建pod:kubectl create -f pod-configmap.yaml
6、查看pod:kubectl get pod pod-configmap -ndev
-----------------------------------------------------------------
NAME READY STATUS RESTARTS AGE
pod-configmap 1/1 Running 0 34s
----------------------------------------------------------------
7、进入pod: kubectl exec -it pod-configmap -ndev /bin/sh
·进到挂载的目录下:# cd /configmap/config
·查看:
-------------------------------------------------------------------------
[root@master-1 home]# kubectl exec -it pod-configmap -ndev /bin/sh
# cd /configmap/config
# ls
info
# more info
username:admin password:123456 #这个就是第一步创建的configMap是配置的信息、说明将configmap挂载到了容器内了
---------------------------------------------------------------------------------------------------------------
8、configMap还支持信息的动态更新
·编辑configMap的信息:kubectl edit configmap configmap -n dev
·将password改为1234567890
--------------------------------------------------------------------
apiVersion: v1
data:
info: username:admin password:1234567890
kind: ConfigMap
-----------------------------------------------------------------------
·在进入容器中查看:kubectl exec -it pod-configmap -ndev /bin/sh
-----------------------------------------------------------------
# cd /configmap/config
# ls
info
# more info
username:admin password:1234567890
---------------------------------------------------------------------
标签:info,configMap,存储,kubectl,44,configmap,pod,config
From: https://www.cnblogs.com/littlecc/p/17700619.html