Kubernetes object using the ConfigMap

Secret ConfigMap and almost the same, but the Secret base64 encryption will be used to create color mode can also be yaml or papers
demonstrate, you create configmap file by
creating a profile my.yaml

name: chenqionghe
light.weight: baby
gym: muscle

Create a file by ConfigMap

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

View configmap objects

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

Created using ConfigMap by pod

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

The process of creating pod

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

View pod has been created

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

Check into the pod and found / app / conf file has been mounted on the 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

Guess you like

Origin www.cnblogs.com/chenqionghe/p/11601241.html