☸️ Fix an Init Container Looping on ConfigMap Reload
An init container that waits on a mounted ConfigMap value (polling a file for a ‘ready’ marker, say) can get stuck restarting forever if the ConfigMap was updated out from under it mid-wait — kubelet’s ConfigMap volume sync interval means the mounted file can briefly disappear or go stale during propagation, and an init container’s restart policy always matches the pod’s, so a transient read failure there restarts the whole pod rather than just retrying the read.
🔎 The Problem
initContainers:
- name: wait-for-config
image: busybox
command: ["sh", "-c", "until grep -q ready /cfg/status; do sleep 2; done"]
volumeMounts:
- name: cfg
mountPath: /cfg
# kubectl get pod shows:
# Init:CrashLoopBackOff restartCount: 14
# right after a `kubectl apply` touched the backing ConfigMap
✅ Fix: Make the Wait Loop Tolerant of a ConfigMap Mid-Update
- Add a short retry-with-backoff loop inside the init container’s own script around the file read, instead of letting any single failed read crash the container and trigger the pod’s full restart policy.
- Set
terminationGracePeriodSecondsaside and instead cap the init container’s own loop with a sane timeout so a genuinely broken config fails fast with a clear log line, rather than crash-looping silently. - Prefer projecting the ConfigMap as an environment variable snapshot taken at pod start for values that don’t need to be live-reloaded, so an init container never has to race a volume sync at all.
🚨 Why This Is Dangerous
- CrashLoopBackOff’s exponential backoff means a pod that hit this during a routine config rollout can sit unready for several minutes even after the ConfigMap finished propagating cleanly.
An init container that waits on a file is really waiting on kubelet’s own sync timing — treat a bad read as ‘try again’, not as ‘crash the pod’.




