Monday, 27 June 2022

Demo ConfigMap in Kubernetes

 

cat configmap.yaml

apiVersion: v1

data:

  key1: SOMESUPERIMPORTANT

kind: ConfigMap

metadata:

  name: my-configmap


cat configmap-pod.yaml

apiVersion: v1

kind: Pod

metadata:

  name: pod-configmap

spec:

  containers:

    - name: test-container

      image: k8s.gcr.io/busybox

      command: [ "/bin/sh", "-c", "env" ]

      env:

        - name: KEY1_CONFIG_MAP

          valueFrom:

            configMapKeyRef:

              name: my-configmap

              key: key1

  restartPolicy: Never


kubectl apply -f configmap.yaml

configmap/my-configmap created


kubectl get cm

NAME               DATA   AGE

kube-root-ca.crt   1      28h

my-configmap       1      42s


kubectl get cm my-configmap

NAME           DATA   AGE

my-configmap   1      58s


kubectl get cm my-configmap -o yaml

apiVersion: v1

data:

  key1: SOMESUPERIMPORTANT

kind: ConfigMap

metadata:

  annotations:

    kubectl.kubernetes.io/last-applied-configuration: |

      {"apiVersion":"v1","data":{"key1":"SOMESUPERIMPORTANT"},"kind":"ConfigMap","metadata":{"annota                                                                                         tions":{},"name":"my-configmap","namespace":"default"}}

  creationTimestamp: "2022-06-24T23:04:38Z"

  name: my-configmap

  namespace: default

  resourceVersion: "36974"

  uid: 59c6bf6e-28f0-4de3-884b-52918aaa977e


#create pod

kubectl apply -f configmap-pod.yaml

pod/pod-configmap created


kubectl get po

NAME            READY   STATUS      RESTARTS   AGE

nginx           1/1     Running     0          28h

pod-configmap   0/1     Completed   0          7s


kubectl logs pod-configmap

KUBERNETES_PORT=tcp://10.96.0.1:443

KUBERNETES_SERVICE_PORT=443

HOSTNAME=pod-configmap

SHLVL=1

HOME=/root

KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

KUBERNETES_PORT_443_TCP_PORT=443

KUBERNETES_PORT_443_TCP_PROTO=tcp

KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443

KUBERNETES_SERVICE_PORT_HTTPS=443

KEY1_CONFIG_MAP=SOMESUPERIMPORTANT

PWD=/

KUBERNETES_SERVICE_HOST=10.96.0.1


No comments:

Post a Comment