ConfigMaps: K8S – 2
We looked at using the environment variables using the configmap in the last blog.
The config map remains the same but now in YAML.
apiVersion: v1
kind: ConfigMap
metadata:
  name: happy-faces-mnt
data:
  data.values: |-
    my.name=saurabh
    my.profession=engineerI will use this to mount it to a container and then see the contents of the file.
apiVersion: v1
kind: Pod
metadata:
  name: happy-pod
spec:
  containers:
  - name: bbox-pod
    image: busybox:latest
    command: ['sh','-c',"echo hello world! && sleep 3600"]
    volumeMounts:
    - name: my-volume
      mountPath: /etc/values
      readOnly: true
  volumes:
  - name: my-volume
    configMap:
      name: happy-faces-mntHave added a volume and mount.
volumes:
  - name: my-volume
    configMap:
      name: happy-faces-mntconfigMap listing for my machine is as under
k get cm
NAME              DATA   AGE
happy-faces-mnt   1      36mk describe cm
Name:         happy-faces-mnt
Namespace:    default
Labels:       <none>
Annotations:  
Data
====
data.values:
----
my.name=saurabh
my.profession=engineer
Events:  <none>Run the pod
k get pods
NAME        READY   STATUS    RESTARTS   AGE
happy-pod   1/1     Running   0          8m21sCheck the mounted volume using
k exec pod/happy-pod -- cat /etc/values/data.values
my.name=saurabh
my.profession=engineerThe content of the file are shown.
