Kubernetes(K8S) 配置管理-ConfigMap 介绍
作用:存储不加密数据到 etcd,让 Pod 以变量或者 Volume 挂载到容器中场景:配置文件
创建配置文件
redis.properties
redis.host=127.0.0.1
redis.port=6379
redis.password=123456创建 ConfigMap
# 根据 redis.properties 创建 redis-config
# kubectl create configmap redis-config --from-file=redis.properties
# 查看 configmap
# kubectl get cm
# 查看 redis-config 的详情
# kubectl describe cm redis-config以 Volume 的形式进行挂载到 pod 容器中
cm.yaml
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: busybox
image: busybox
command: [ "/bin/sh","-c","cat /etc/config/redis.properties" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: redis-config
restartPolicy: Never# 创建 yaml文件
# vi cm.yaml
# 创建pod
# kubectl apply -f cm.yaml
# 启动后可以查看日志
# kubectl logs mypod以变量的形式进行挂载
创建 yaml,声明变量信息 configmap 创建
myconfig.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfig
namespace: default
data:
special.level: info
special.type: hello config-var.yaml
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: busybox
image: busybox
command: [ "/bin/sh", "-c", "echo $(LEVEL) $(TYPE)" ]
env:
- name: LEVEL
valueFrom:
configMapKeyRef:
name: myconfig
key: special.level
- name: TYPE
valueFrom:
configMapKeyRef:
name: myconfig
key: special.type
restartPolicy: Never# vi myconfig.yaml
# kubectl apply -f myconfig.yaml
# 以变量形式进行挂载
# vi config-var.yaml
# kubectl apply -f config-var.yaml
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]