Kubernetes的ConfigMap对象使用

ConfigMap和Secret几乎一样,只是Secret会用base64加密,创建方式也可以彩yaml或者文件方式
下面演示一下通过文件创建configmap
创建配置文件my.yaml

name: chenqionghe
light.weight: baby
gym: muscle

通过文件创建ConfigMap

kubectl create configmap my-config --from-file=./my.yaml

查看configmap对象

root@VM-0-8-ubuntu:/home/ubuntu# kubectl get configmaps my-config -o yaml
apiVersion: v1
data:
  my.yaml: |
    name: chenqionghe
    light.weight: baby
    gym: muscle
kind: ConfigMap
metadata:
  creationTimestamp: 2019-09-27T16:43:53Z
  name: my-config
  namespace: default
  resourceVersion: "2139336"
  selfLink: /api/v1/namespaces/default/configmaps/my-config
  uid: fd4aeb09-e145-11e9-8c22-f242c645cfec

创建通过pod使用ConfigMap

apiVersion: v1
kind: Pod
metadata:
  name: test-configmap
spec:
  containers:
  - name: test-configmap
    image: busybox
    args:
    - sleep
    - "86400"
    volumeMounts:
    - name: config-volume
      mountPath: "/app/conf"
      readOnly: true
  volumes:
  - name: config-volume
    configMap:
          name: my-config

执行创建pod

root@VM-0-8-ubuntu:/home/ubuntu# kubectl apply -f test-config-pod.yaml
pod/test-configmap created

查看pod已经创建

root@VM-0-8-ubuntu:/home/ubuntu# kubectl get po
NAME READY STATUS RESTARTS AGE
demo-deployment-555958bc44-llhr9 1/1 Running 0 20d
test-configmap 1/1 Running 0 1m

进入pod查看,发现/app/conf已经挂载上了my.yaml文件

root@VM-0-8-ubuntu:/home/ubuntu# kubectl exec -it test-configmap -- /bin/sh
/ # ls /app/conf
my.yaml
/ # cat /app/conf/my.yaml
name: chenqionghe
light.weight: baby
gym: muscl
posted @ 2019-09-28 01:20  雪山飞猪  阅读(1691)  评论(0编辑  收藏  举报