|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

 

 

posted on   yanqi_vip  阅读(9)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示