CKAD field manual
k8s ConfigMap YAML example
Create the ConfigMap, then reference it from the container. Updating it does not restart the Pod.
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/
apiVersion: v1
kind: ConfigMap
metadata:
name: app
namespace: default
data:
LOG_LEVEL: info
PORT: "8080"
nginx.conf: |
worker_processes 1;
spec:
containers:
- name: app
image: nginx:1.27
env:
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: app
key: LOG_LEVEL
envFrom:
- configMapRef:
name: app
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