In Kubernetes, workloads often rely on ConfigMaps or Secrets for configuration data. However, when these resources change, pods do not automatically pick up the updates. Config generators (and secret generators) solve this by automating rollouts whenever underlying ConfigMaps or Secrets are modified. In this lesson, we’ll demonstrate this problem and prepare for the next section on generators.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Initial Setup
1. Create a ConfigMap for Database Credentials
First, define a ConfigMap to hold your database password. In production, you should use a Secret, but for demonstration the behavior is identical.Use a Secret in real deployments to protect sensitive data.
configmap.yaml and apply:
2. Deploy an NGINX Pod Referencing the ConfigMap
Next, deploy an NGINX container that injects the password as an environment variable:deployment.yaml and apply:
Verifying the Environment Variable
-
List the running pods:
-
Exec into the NGINX pod and print the
DB_PASSWORD:
Changing the Password
After some time, update the database password in your ConfigMap:Kubernetes does not automatically redeploy pods when a referenced ConfigMap or Secret is updated. You must manually trigger a restart.
Manual Rollout Restart
To pick up the new password, force a rollout restart of the deployment:Common Kubectl Commands
| Command | Purpose |
|---|---|
kubectl apply -f configmap.yaml | Create or update a ConfigMap |
kubectl apply -f deployment.yaml | Create or update a Deployment |
kubectl get pods | List all pods |
kubectl exec <pod> -- printenv | Inspect environment variables in pod |
kubectl rollout restart deployment <name> | Restart pods to pick up changes |