CKAD field manual

k8s ConfigMap YAML example

Create the ConfigMap, then reference it from the container. Updating it does not restart the Pod.

A ship is loaded with identical labeled crates from a wall of storage before departure. A ship is loaded with identical labeled crates from a wall of storage before departure.
Create
kubectl create configmap app --from-literal=LOG_LEVEL=info --from-literal=PORT=8080
kubectl create configmap nginx --from-file=nginx.conf
kubectl create configmap nginx --from-file=conf.d/
ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
  name: app
  namespace: default
data:
  LOG_LEVEL: info
  PORT: "8080"
  nginx.conf: |
    worker_processes 1;
env / envFrom
spec:
  containers:
    - name: app
      image: nginx:1.27
      env:
        - name: LOG_LEVEL
          valueFrom:
            configMapKeyRef:
              name: app
              key: LOG_LEVEL
      envFrom:
        - configMapRef:
            name: app
As a file
spec:
  containers:
    - name: app
      image: nginx:1.27
      volumeMounts:
        - name: cfg
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
  volumes:
    - name: cfg
      configMap:
        name: app

Fields

envFrom
Every key becomes an env var. One key: valueFrom + configMapKeyRef.
configMapKeyRef
One key. name is the ConfigMap, key is the entry.
subPath
Mount one key as one file. Without it, every key becomes a file in mountPath.
configMap
Updating the ConfigMap does not restart the Pod.

Watch

  • One key: valueFrom + configMapKeyRef. Every key: envFrom. A file: volume + volumeMount.
  • subPath mounts one key as one file. Without subPath, every key becomes a file in mountPath.
  • Changing a ConfigMap does not restart the Pod. Delete the Pod, or the app must re-read the file.

Official docs ConfigMaps

Practice these objects on a live cluster →