0
0
Kubernetesdevops~5 mins

Updating ConfigMaps and propagation in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
ConfigMaps store configuration data for your apps in Kubernetes. When you update a ConfigMap, your app needs to get the new data to work correctly without restarting everything manually.
When you want to change app settings without rebuilding the container image.
When you need to update environment variables for running pods.
When you want to apply new configuration to multiple pods at once.
When you want to avoid downtime by updating config without restarting pods manually.
When you want to test new configuration quickly in a live environment.
Config File - configmap.yaml
configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-config
  namespace: default
data:
  app.properties: |
    log_level=info
    max_connections=100

This file creates a ConfigMap named example-config in the default namespace.

The data section holds configuration key-value pairs your app can use.

Commands
This command creates or updates the ConfigMap in Kubernetes with the settings from the file.
Terminal
kubectl apply -f configmap.yaml
Expected OutputExpected
configmap/example-config created
This command shows the current content of the ConfigMap to verify your changes.
Terminal
kubectl get configmap example-config -o yaml
Expected OutputExpected
apiVersion: v1 data: app.properties: | log_level=info max_connections=100 kind: ConfigMap metadata: name: example-config namespace: default resourceVersion: "12345" uid: 123e4567-e89b-12d3-a456-426614174000
-o yaml - Outputs the ConfigMap in YAML format for easy reading
This command restarts the pods in the deployment so they load the updated ConfigMap.
Terminal
kubectl rollout restart deployment example-deployment
Expected OutputExpected
deployment.apps/example-deployment restarted
This command lists pods with the label app=example-app to check their status after restart.
Terminal
kubectl get pods -l app=example-app
Expected OutputExpected
NAME READY STATUS RESTARTS AGE example-deployment-5d8f7c9d7f-abc12 1/1 Running 0 10s example-deployment-5d8f7c9d7f-def34 1/1 Running 0 10s
-l app=example-app - Filters pods by label to show only relevant pods
Key Concept

Updating a ConfigMap alone does not update running pods; you must restart pods or trigger a rollout to apply changes.

Common Mistakes
Updating the ConfigMap but not restarting pods or deployment.
Pods keep using old config because they load ConfigMaps only at start.
After updating the ConfigMap, run 'kubectl rollout restart deployment <deployment-name>' to reload config.
Editing ConfigMap with 'kubectl edit' but forgetting to save changes.
No changes are applied if edits are not saved properly.
Make sure to save and exit the editor to apply changes.
Assuming ConfigMap updates automatically propagate to pods without restart.
Kubernetes does not auto-update running pods with new ConfigMap data.
Manually restart pods or deployment to pick up new ConfigMap values.
Summary
Create or update ConfigMaps using 'kubectl apply -f configmap.yaml'.
Verify ConfigMap content with 'kubectl get configmap <name> -o yaml'.
Restart pods or deployment with 'kubectl rollout restart deployment <name>' to apply changes.
Check pod status with 'kubectl get pods' filtered by labels.