CC00017.CloudKubernetes——|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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值