📖 Scenario: You are managing a Kubernetes cluster for a small web application. The application uses a ConfigMap to store configuration settings like the welcome message. You need to update the ConfigMap and see how the changes propagate to the running pods.
🎯 Goal: Learn how to create a ConfigMap, update it, and verify that the changes propagate to pods using volume mounts.
📋 What You'll Learn
Create a ConfigMap with a key-value pair
Create a pod that uses the ConfigMap as a volume
Update the ConfigMap with a new value
Verify the updated value inside the pod
💡 Why This Matters
🌍 Real World
ConfigMaps are used in Kubernetes to separate configuration from container images. Updating ConfigMaps and understanding how changes propagate helps keep applications flexible and easy to manage.
💼 Career
DevOps engineers and Kubernetes administrators frequently update ConfigMaps to change application behavior without rebuilding images. Knowing how to update and verify ConfigMaps is essential for managing live applications.
Progress0 / 4 steps
1
Create a ConfigMap with initial data
Create a ConfigMap named app-config with a key welcome_message and value Hello, Kubernetes! using the kubectl create configmap command.
Kubernetes
Hint
Use kubectl create configmap app-config --from-literal=welcome_message='Hello, Kubernetes!' to create the ConfigMap.
2
Create a pod that uses the ConfigMap as a volume
Create a pod named configmap-pod using the busybox image. Mount the app-config ConfigMap as a volume at /etc/config. Use the command sleep 3600 to keep the pod running.
Kubernetes
Hint
Use kubectl run to create the pod and patch it to add the ConfigMap volume and mount.
3
Update the ConfigMap with a new welcome message
Update the app-config ConfigMap to change the welcome_message value to Welcome to Kubernetes! using the kubectl create configmap --from-literal --dry-run=client -o yaml | kubectl apply -f - pattern.
Kubernetes
Hint
Use kubectl create configmap app-config --from-literal=welcome_message='Welcome to Kubernetes!' --dry-run=client -o yaml | kubectl apply -f - to update the ConfigMap.
4
Verify the updated ConfigMap value inside the pod
Use kubectl exec to open a shell inside the configmap-pod pod and use cat /etc/config/welcome_message to display the updated welcome message.
Kubernetes
Hint
Use kubectl exec configmap-pod -- cat /etc/config/welcome_message to see the updated message inside the pod.
Practice
(1/5)
1. What happens when you update a ConfigMap in Kubernetes without restarting the pods using it?
easy
A. Pods continue using the old ConfigMap values until restarted
B. Pods automatically reload the new ConfigMap values immediately
C. Kubernetes deletes the pods using the old ConfigMap
D. ConfigMap update fails if pods are running
Solution
Step 1: Understand ConfigMap behavior on update
Updating a ConfigMap does not notify or refresh pods automatically.
Step 2: Effect on running pods
Pods keep using the old ConfigMap data until they are restarted or redeployed.
Final Answer:
Pods continue using the old ConfigMap values until restarted -> Option A
Quick Check:
Pods do not auto-refresh ConfigMaps = B [OK]
Hint: Pods need restart to use updated ConfigMaps [OK]
Common Mistakes:
Assuming pods auto-refresh ConfigMap changes
Thinking ConfigMaps update triggers pod restart automatically
Believing ConfigMap updates delete pods
2. Which command correctly updates a ConfigMap named app-config from a file config.yaml?
easy
A. kubectl update configmap app-config --from-file=config.yaml
B. kubectl edit configmap app-config --from-file=config.yaml
C. kubectl replace configmap app-config --from-file=config.yaml
Use create with dry-run + apply to update ConfigMap = C [OK]
Hint: Use create with dry-run and apply to update ConfigMap [OK]
Common Mistakes:
Using 'kubectl update' which is not a valid command
Trying to edit ConfigMap with --from-file option
Using replace without proper YAML input
3. Given a pod using a ConfigMap mounted as a volume, what is the output of cat /etc/config/app.properties inside the pod immediately after updating the ConfigMap but before restarting the pod?
medium
A. Shows the updated content from the ConfigMap
B. Shows the old content from the ConfigMap before update
C. File is empty because ConfigMap is not mounted
D. Command returns an error because ConfigMap changed
Solution
Step 1: Understand ConfigMap volume mount behavior
ConfigMap mounted as volume is projected as files inside pod at start time.
Step 2: Effect of ConfigMap update on mounted files
Files inside pod do not update automatically; they keep old content until pod restart.
Final Answer:
Shows the old content from the ConfigMap before update -> Option B
Quick Check:
Mounted ConfigMap files do not auto-update = A [OK]
Hint: Mounted ConfigMap files update only after pod restart [OK]
Common Mistakes:
Assuming mounted files auto-refresh on ConfigMap update
Expecting empty files if ConfigMap changed
Thinking command errors due to ConfigMap update
4. You updated a ConfigMap but your pods still use old values. Which command fixes this without deleting pods manually?
medium
A. kubectl rollout restart deployment/myapp
B. kubectl delete pod -l app=myapp
C. kubectl apply -f configmap.yaml
D. kubectl configmap refresh myapp
Solution
Step 1: Identify how to refresh pods after ConfigMap update
Pods must restart to load new ConfigMap values.
Step 2: Use rollout restart to restart pods gracefully
Command 'kubectl rollout restart' triggers pod restart without manual deletion.
Final Answer:
kubectl rollout restart deployment/myapp -> Option A
Quick Check:
Use rollout restart to refresh pods = D [OK]
Hint: Use rollout restart to refresh pods after ConfigMap update [OK]
Common Mistakes:
Deleting pods manually instead of rollout restart
Expecting apply to restart pods automatically
Using non-existent commands like configmap refresh
5. You have a deployment using a ConfigMap for environment variables. After updating the ConfigMap, you want all pods to use the new values without downtime. What is the best approach?
hard
A. Update the ConfigMap and wait; pods auto-refresh environment variables
B. Delete all pods manually to force recreation with new ConfigMap
C. Update the ConfigMap and run kubectl rollout restart deployment/myapp
D. Edit each pod to mount the new ConfigMap version