DEV Community

Latchu@DevOps
Latchu@DevOps

Posted on

⭐ Scenario #6: Auto-Update ConfigMap Without Restarting the Pod (Using Volume Mount)

This scenario demonstrates:

✔ ConfigMap mounted as a file
✔ Pod picks up changes automatically without restart
✔ Application reads updated data from the file in real time
✔ You verify live updates

This is how apps like Nginx, Prometheus, and Spring Boot use dynamic config reloads.


🟩 Step 1 — Create a ConfigMap

Create dynamic-configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: dynamic-config
data:
  message: "Hello from ConfigMap v1"
Enter fullscreen mode Exit fullscreen mode

Apply it:

kubectl apply -f dynamic-configmap.yaml
Enter fullscreen mode Exit fullscreen mode

🟩 Step 2 — Create a Pod That Mounts the ConfigMap as a File

Create pod-dynamic-config.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: dynamic-config-pod
spec:
  containers:
    - name: demo-container
      image: busybox
      command: ["sh", "-c", "while true; do echo \"Message: $(cat /config/message)\"; sleep 3; done"]
      volumeMounts:
        - name: config-volume
          mountPath: /config
  volumes:
    - name: config-volume
      configMap:
        name: dynamic-config
Enter fullscreen mode Exit fullscreen mode

Apply it:

kubectl apply -f pod-dynamic-config.yaml
Enter fullscreen mode Exit fullscreen mode

Wait for ready:

kubectl wait --for=condition=Ready pod/dynamic-config-pod --timeout=60s
Enter fullscreen mode Exit fullscreen mode

1


🟩 Step 3 — View Live Output From the Pod

Open logs:

kubectl logs -f dynamic-config-pod
Enter fullscreen mode Exit fullscreen mode

You will see:

Message: Hello from ConfigMap v1
Message: Hello from ConfigMap v1
...
Enter fullscreen mode Exit fullscreen mode

Keep this logs window open.

2


🟩 Step 4 — Update the ConfigMap Without Restarting the Pod

Edit the ConfigMap:

kubectl edit configmap dynamic-config
Enter fullscreen mode Exit fullscreen mode

Change the value:

message: "Hello from ConfigMap v2 - UPDATED LIVE"
Enter fullscreen mode Exit fullscreen mode

Save & exit.


🟩 Step 5 — Watch the Pod Update Automatically (NO Restart Needed)

Your logs will automatically switch:

Message: Hello from ConfigMap v1
Message: Hello from ConfigMap v1
Message: Hello from ConfigMap v2 - UPDATED LIVE
Message: Hello from ConfigMap v2 - UPDATED LIVE
Enter fullscreen mode Exit fullscreen mode

✔ No pod restart
✔ No rollout
✔ No manual intervention

3


💡 WHY does this work?

Method Auto-Update? Reason
ConfigMap → env variables ❌ No Env vars are fixed at Pod startup
ConfigMap → mounted volume ✅ Yes Kubelet updates file symlink every ~1–2 seconds

Kubernetes mounts each ConfigMap entry as a file using a symlink that is automatically refreshed.


⚠️ IMPORTANT NOTE

Although the file updates automatically:

➡ Your application must reload the file dynamically
➡ If the app loads config only at startup, you won’t see updates


🌟 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)