study.

Refresh Configuration with a Rollout · Kubernetes

Why does an application still see the old value after a ConfigMap change?

← Kubernetes

Learn with progress and quizzes

First, understand the concepts.

Separate configuration from images

A ConfigMap holds non-sensitive configuration outside the image. The same image can receive different values in different environments.

Environment variable timing

Values injected from a ConfigMap are read when a container starts. Editing the ConfigMap does not rewrite a running process’s environment.

Explicit new execution

rollout restart creates new Pods that read updated values. Mounted configuration files have different update behavior from environment variables.

Why it matters

Changing configuration and making a process reread it are separate operations. Environment values are established at container startup.

Work through the reasoning

Observe three moments

Start with MODE=first. Change the ConfigMap to second and inspect the same running process: it still sees first. Restart the Deployment and inspect a new Pod: it sees second. Record Pod identities at each step.

Compare mounted files

ConfigMap volume updates can propagate later, but applications must reread them. subPath mounts do not receive automatic updates. Design both delivery and application reload behavior.

Learn by doing.

Use kubectl, a personal practice Kubernetes cluster, and a POSIX shell. Check the context and use the dedicated namespace in each lab. Cleanup deletes all resources in that practice namespace.

Deploy an application reading MODE=first, change the ConfigMap to second, and compare values before and after restarting the rollout.

kubectl config current-context
kubectl create namespace study-k8s-config --dry-run=client -o yaml | kubectl apply -f -
kubectl create configmap settings --from-literal=MODE=first -n study-k8s-config --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -n study-k8s-config -f - <<'YAML'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: reader
spec:
  replicas: 1
  selector:
    matchLabels: {app: reader}
  template:
    metadata:
      labels: {app: reader}
    spec:
      containers:
      - name: reader
        image: busybox:1.36
        command: ["sleep", "3600"]
        envFrom:
        - configMapRef: {name: settings}
YAML
kubectl rollout status deployment/reader -n study-k8s-config --timeout=120s
kubectl exec deployment/reader -n study-k8s-config -- printenv MODE
kubectl create configmap settings --from-literal=MODE=second -n study-k8s-config --dry-run=client -o yaml | kubectl apply -f -
kubectl exec deployment/reader -n study-k8s-config -- printenv MODE
kubectl rollout restart deployment/reader -n study-k8s-config
kubectl rollout status deployment/reader -n study-k8s-config --timeout=120s
kubectl exec deployment/reader -n study-k8s-config -- printenv MODE

How to check your result

Expect first initially and immediately after the ConfigMap edit, then second after rollout restart. If the variable is missing, check the envFrom reference and namespace.

Clean up practice resources

Run after checking the result. Confirm these resources belong to your practice run and contain no data you need to keep.

kubectl delete namespace study-k8s-config

Apply what you learned

The app reads a configuration file only at startup. Does changing the mounted file immediately change application behavior?

Reveal the reasoning after trying

No. The app may need a reload mechanism or a new execution. Check the file contents, the value actually in use, and replacement readiness separately.

Ready to check your understanding?

What is usually required to apply a changed ConfigMap environment value?

  1. Only reading the ConfigMap
  2. Starting a new container
  3. Deleting the Service
  4. Removing Pod labels
Reveal the reasoning after trying

Starting a new container

Environment values are read at startup. A new Pod or container must read the updated configuration.

Official documentation · Refresh Configuration with a Rollout