Updating ConfigMaps and propagation in Kubernetes - Time & Space Complexity
When we update ConfigMaps in Kubernetes, we want to know how the time to apply changes grows as the number of pods using the ConfigMap increases.
We ask: How does updating and propagating ConfigMap changes scale with more pods?
Analyze the time complexity of the following Kubernetes commands.
kubectl create configmap app-config --from-file=config.yaml
kubectl apply -f deployment.yaml
kubectl rollout restart deployment/my-app
This sequence creates a ConfigMap, applies a deployment that uses it, and restarts pods to pick up changes.
Look for repeated actions that affect time.
- Primary operation: Restarting each pod in the deployment to load the new ConfigMap.
- How many times: Once per pod in the deployment, sequentially or in batches.
As the number of pods grows, the time to restart all pods grows too.
| Input Size (pods) | Approx. Operations (pod restarts) |
|---|---|
| 10 | 10 restarts |
| 100 | 100 restarts |
| 1000 | 1000 restarts |
Pattern observation: The time grows directly with the number of pods to restart.
Time Complexity: O(n)
This means the time to update and propagate ConfigMap changes grows linearly with the number of pods.
[X] Wrong: "Updating a ConfigMap automatically updates all pods instantly without extra time."
[OK] Correct: Pods must restart or reload to see changes, so time depends on how many pods need updating.
Understanding how updates scale helps you design systems that handle changes smoothly as they grow.
What if we used a sidecar container to watch ConfigMap changes and reload pods without restarting? How would the time complexity change?
Practice
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 AQuick Check:
Pods do not auto-refresh ConfigMaps = B [OK]
- Assuming pods auto-refresh ConfigMap changes
- Thinking ConfigMaps update triggers pod restart automatically
- Believing ConfigMap updates delete pods
app-config from a file config.yaml?Solution
Step 1: Understand updating ConfigMap from file
Direct update requires creating new YAML and applying it.Step 2: Use dry-run and apply for update
Command C creates new ConfigMap YAML from file and applies it, updating existing ConfigMap.Final Answer:
kubectl create configmap app-config --from-file=config.yaml --dry-run=client -o yaml | kubectl apply -f - -> Option DQuick Check:
Use create with dry-run + apply to update ConfigMap = C [OK]
- Using 'kubectl update' which is not a valid command
- Trying to edit ConfigMap with --from-file option
- Using replace without proper YAML input
cat /etc/config/app.properties inside the pod immediately after updating the ConfigMap but before restarting the pod?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 BQuick Check:
Mounted ConfigMap files do not auto-update = A [OK]
- Assuming mounted files auto-refresh on ConfigMap update
- Expecting empty files if ConfigMap changed
- Thinking command errors due to ConfigMap update
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 AQuick Check:
Use rollout restart to refresh pods = D [OK]
- Deleting pods manually instead of rollout restart
- Expecting apply to restart pods automatically
- Using non-existent commands like configmap refresh
Solution
Step 1: Understand environment variable update behavior
Pods do not auto-refresh environment variables from ConfigMap updates.Step 2: Use rollout restart for zero downtime update
Rolling restart updates pods one by one, applying new ConfigMap values without downtime.Final Answer:
Update the ConfigMap and run kubectl rollout restart deployment/myapp -> Option CQuick Check:
Rollout restart updates pods gracefully = A [OK]
- Expecting pods to auto-refresh env vars
- Deleting pods causing downtime
- Editing pods directly which is not recommended
Ready to prove it?
Pass the test and this pattern moves unknown
