Q: How do you make a pod restart on config change without a code change?
A pod restart on config change is not automatic: Kubernetes only rolls pods when the Pod template changes, so you must make the config change show up in the template (a checksum annotation, a hashed ConfigMap name) or trigger a.
Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: <strong>A pod restart on config change is not automatic:</strong> Kubernetes only rolls pods when the Pod template changes, so you must make the config change show up in the template (a checksum annotation, a hashed ConfigMap name) or trigger a rollout explicitly with <code>kubectl rollout restart</code>. Interviewers ask this because ConfigMap and Secret updates are a classic source of silent drift: the object changes, the running pods do not. A strong answer explains how each consumption mode behaves (env vars, volume mounts, <code>subPath</code>), then picks a repeatable, GitOps-friendly mechanism instead of manually deleting pods.
Mental model: why pods ignore config updates
Before choosing a trigger, know how the container actually consumes the config, because that decides whether a restart is needed at all.
- Env vars: values from
env.valueFrom.configMapKeyReforenvFromare resolved once at container start. Editing the ConfigMap never changes a running process, so a restart is mandatory. - Volume mounts: files in a mounted ConfigMap or Secret volume are refreshed by the kubelet after a delay (sync period plus cache TTL, so it can take a minute or more). The application must re-read the file or watch for changes.
- subPath mounts: a ConfigMap mounted with
subPathis never updated in place. This surprises many teams, and a restart is the only fix. - Immutable objects: if the ConfigMap has
immutable: trueyou cannot edit it at all. You create a new object and point the workload at it, which naturally triggers a rollout.
Hands-on: pod restart on config change with rollout restart
The fastest option is a rolling restart, which respects readiness probes, maxUnavailable and PodDisruptionBudgets, unlike deleting pods by hand.
# 1. Update the config
kubectl -n prod apply -f app-config.yaml
# 2. Roll the pods so they pick it up
kubectl -n prod rollout restart deployment/my-app
# 3. Wait for the rollout to finish (non-zero exit on failure/timeout)
kubectl -n prod rollout status deployment/my-app --timeout=180s
# 4. Confirm the pods are new
kubectl -n prod get pods -l app=my-app -o wide
- Trigger:
kubectl rollout restart deployment/my-appstamps akubectl.kubernetes.io/restartedAtannotation on the Pod template, which creates a new ReplicaSet. It also works for StatefulSets and DaemonSets. - Watch it:
kubectl rollout statusblocks until the new ReplicaSet is fully available, so you can use it as a CI gate. - Limitation: it is imperative. Nothing in Git records that a restart happened, and it does not detect config drift by itself.
- Rollback:
kubectl rollout undoreturns to the previous ReplicaSet if the new config is bad.
Declarative triggers: checksum annotation or hashed ConfigMap
For GitOps, make the config content part of the Pod template so any change produces a new template hash and a normal rolling update.
# Helm: deployment.yaml (pod template metadata)
spec:
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
# Kustomize: kustomization.yaml
configMapGenerator:
- name: my-app-config
files:
- app.properties
# renders my-app-config-<hash>; Deployment refs are rewritten automatically
- Helm checksum annotation: add the pod annotation
checksum/configwith the sha256 of the rendered ConfigMap template. When the ConfigMap changes, the annotation changes, andhelm upgraderolls the Deployment. - Kustomize generator:
configMapGeneratorappends a content hash to the name and rewrites references, so every edit creates a new ConfigMap and a new rollout. Old ConfigMaps can be garbage-collected later. - Benefit: rollback is a Git revert, because the previous config name is referenced by the previous Pod template.
- Trade-off: a hash change restarts every pod even for a harmless comment edit, so keep volatile data out of the hashed object.
Controller-based reload with Reloader and hot reload
If config changes outside the deployment pipeline, a controller can watch the objects and roll the workloads for you.
- Reloader: the open-source Stakater Reloader watches ConfigMaps and Secrets and triggers a rolling update on annotated workloads, for example
reloader.stakater.com/auto: "true". Review its RBAC, since it needs write access to workloads. - Hot reload instead of restart: apps that support SIGHUP or a file watcher (nginx reload, Prometheus
/-/reload) can avoid restarts, using a sidecar to signal the main process. Test that the reload truly applies the setting. - Secrets: the same logic applies. Rotating a Secret does nothing until the pod restarts or re-reads the mounted file.
- Blast radius: auto-restart on every change can cause a thundering herd if many workloads share one ConfigMap, so scope ConfigMaps per application.
Verification and failure modes
Confirm that the new config is really in effect, not just that new pods exist.
- Check the template:
kubectl get deploy my-app -o jsonpath='{.spec.template.metadata.annotations}'should show the new checksum or restartedAt value. - Check the process:
kubectl exec deploy/my-app -- env | grep LOG_LEVELor read the mounted file to confirm the value the app really sees. - Bad config: a crash-looping new ReplicaSet leaves old pods running because rolling updates stop when new pods never become ready. Watch
rollout statusand alert onprogressDeadlineSecondsbeing exceeded. - Validation: lint ConfigMaps in CI (schema or dry-run with
kubectl apply --dry-run=server) so broken config never reaches the rollout.
- Pods only roll when the Pod template changes, so a ConfigMap edit alone never restarts anything; env vars are read at start, and mounted files update lazily.
- I make config part of the template using a checksum annotation or a hashed ConfigMap name, and use kubectl rollout restart for ad hoc cases, then confirm with rollout status.
- For config changed outside CI, I use a reload controller like Reloader with scoped ConfigMaps and keep probes and PDBs correct.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Assuming editing a ConfigMap updates running pods Env vars are fixed at container start, and subPath mounts never refresh, so the app keeps stale values.
- Deleting pods manually to pick up config It bypasses rolling-update safeguards and can drop capacity below the PodDisruptionBudget.
- Sharing one giant ConfigMap across many workloads with auto-reload A single edit restarts every consumer at once and creates a thundering herd.
- Not testing the config before rolling A bad value creates crash-looping pods; the rollout stalls and you must undo under pressure.