|NO.Z.00017|——————————|CloudNative|——|Kubernetes&pod操作.V05|——|configmap不加密数据|
一、configMap:不加密数据

二、configmap操作流程
### --- 将历史环境删除
[root@k8s-master ~]# kubectl delete secret --all
secret "default-token-686hn" deleted
secret "mysecret" deleted
[root@k8s-master ~]# kubectl delete Pod --all
pod "ds-test-fv2kx" deleted
pod "ds-test-gzxlq" deleted
pod "hello-1614010320-rh726" deleted
pod "hello-1614010380-mt6dc" deleted
pod "hello-1614010440-dcqzj" deleted
pod "mypod" deleted
pod "nginx-f89759699-gp9rr" deleted
### --- 将配置文件上传到服务器
[root@k8s-master ~]# ls cm* config* myconfig* redis*
cm.yaml config-var.yaml myconfig.yaml redis.properties
### --- 常见配置文件redis.properties
[root@k8s-master ~]# vim redis.properties
redis.host=127.0.0.1
redis.port=6379
redis.password=123456
### --- 创建configmap
[root@k8s-master ~]# kubectl create configmap redis.config --from-file=redis.properties
configmap/redis.config created
[root@k8s-master ~]# kubectl get cm
NAME DATA AGE
redis.config 1 17s
~~~ 查看它的详细信息
[root@k8s-master ~]# kubectl describe cm redis.config
Name: redis.config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
redis.properties:
----
redis.host=127.0.0.1
redis.port=6379
redis.password=123456
Events: <none>
### --- 以volume的形式挂载到pod里面
[root@k8s-master ~]# vim 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 # configmap的名字
restartPolicy: Never
[root@k8s-master ~]# kubectl apply -f cm.yaml
pod/mypod created
[root@k8s-master ~]# kubectl get pods
mypod 0/1 ContainerCreating 0 7s
~~~ 查看挂载的值
[root@k8s-master ~]# kubectl logs mypod
redis.host=127.0.0.1
redis.port=6379
redis.password=123456
### --- 以变量形式挂载
~~~ 删除历史创建
[root@k8s-master ~]# kubectl delete -f cm.yaml
pod "mypod" deleted
[root@k8s-master ~]# vim myconfig.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfig
namespace: default
data:
special.level: info
special.type: hello
[root@k8s-master ~]# kubectl apply -f myconfig.yaml
configmap/myconfig created
[root@k8s-master ~]# kubectl get cm
NAME DATA AGE
myconfig 2 12s
redis.config 1 15m
~~~ 创建挂载文件
[root@k8s-master ~]# vim 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
[root@k8s-master ~]# kubectl apply -f config-var.yaml
pod/mypod created
[root@k8s-master ~]# kubectl get pods
mypod 0/1 Completed 0 40s
~~~ 查看挂载的值
[root@k8s-master ~]# kubectl logs mypod
info hello
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通