In this scenario you will:
β
Create a ConfigMap
β
Mount it as a volume inside a Pod
β
Update the ConfigMap
β
Watch the Pod automatically see the updated file (no restart needed!)
β
Test real-time behavior
This is one of the most important Kubernetes features for configuration-driven apps.
β Step 1 β Create the ConfigMap
Create a file:
# config-volume-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
welcome.txt: |
Welcome version 1
This is the first config.
Apply it:
kubectl apply -f config-volume-cm.yaml
Verify:
kubectl get configmap app-config -o yaml
β Step 2 β Create a Pod That Mounts the ConfigMap as a Volume
Create file:
# config-volume-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: config-volume-demo
spec:
containers:
- name: nginx
image: nginx:1.25
volumeMounts:
- name: config-volume
mountPath: /usr/share/nginx/html/config # Config file available here
volumes:
- name: config-volume
configMap:
name: app-config
Apply:
kubectl apply -f config-volume-pod.yaml
Check pod:
kubectl get pod config-volume-demo
Wait until Running.
β Step 3 β Verify the Mounted Config File
Exec into the container:
kubectl exec -it config-volume-demo -- bash
Then check:
cat /usr/share/nginx/html/config/welcome.txt
You will see:
Welcome version 1
This is the first config.
β Perfect.
Exit:
exit
β Step 4 β Update the ConfigMap (without restarting Pod)
Edit: config-volume-cm.yaml
# update configmap
data:
welcome.txt: |
Welcome version 2
This config was updated dynamically!
Apply:
kubectl apply -f config-volume-cm.yaml
β Step 5 β Verify Update in the Running Pod (AUTO-UPDATE)
Exec again:
kubectl exec -it config-volume-demo -- bash
Then:
cat /usr/share/nginx/html/config/welcome.txt
EXPECTED OUTPUT:
Welcome version 2
This config was updated dynamically!
β ConfigMap volume updates automatically (no restart required).
β Important Note
β
Volume-mounted ConfigMaps auto-update every ~1β2 seconds, thanks to Kubernetes file projections.
β But config from environment variables does NOT auto-update β requires pod restart.
This is why many apps prefer mounting ConfigMaps as volumes.
β Step 6 β Clean Up
kubectl delete pod config-volume-demo
kubectl delete configmap app-config
π Thanks for reading! If this post added value, a like β€οΈ, follow, or share would encourage me to keep creating more content.
β Latchu | Senior DevOps & Cloud Engineer
βοΈ AWS | GCP | βΈοΈ Kubernetes | π Security | β‘ Automation
π Sharing hands-on guides, best practices & real-world cloud solutions




Top comments (0)