devops

Kubernetes Pod Stuck in Init:0/1, Init:Error, or Init:CrashLoopBackOff: How to Debug and Fix Init Containers

Fix a Kubernetes pod stuck in Init:0/1, Init:Error or Init:CrashLoopBackOff: find the blocking init container, read its logs, then fix the wait loop or exit.

November 24, 2026·11 min read·
#kubernetes#sre#devops#containers#reliability#incident-response

What an Init: status means

A pod whose STATUS starts with Init: has not started any of its application containers yet, because an init container has not exited with code 0. Init containers run one at a time, in the order they are listed, and each must succeed before the next begins. Init:0/1 means zero of one init containers have completed. Init:Error means the current one exited non-zero. Init:CrashLoopBackOff means it has failed repeatedly and the kubelet is waiting before the next attempt. The fix is always the same first move: find which init container is blocking and read its logs, by name, with -c.

That last part is where the time goes. kubectl logs my-pod on a pod in Init: returns an error about the app container waiting to start (PodInitializing), which says nothing. The app container has never run. Everything you need is in the init container.

Step 1: Find the blocking init container

kubectl -n orders get pod api-7c9d8b6f5-x2kqp
NAME                  READY   STATUS     RESTARTS   AGE
api-7c9d8b6f5-x2kqp   0/1     Init:1/3   0          14m

Init:1/3 means the first init container finished and the second is the problem. The third has not been attempted. Get the state of each one:

kubectl -n orders get pod api-7c9d8b6f5-x2kqp -o jsonpath='{range .status.initContainerStatuses[*]}{.name}{"\t"}{.state}{"\t restarts="}{.restartCount}{"\n"}{end}'
fetch-config    {"terminated":{"exitCode":0,"reason":"Completed",...}}   restarts=0
wait-for-db     {"running":{"startedAt":"2026-11-24T02:11:07Z"}}         restarts=0
run-migrations  {"waiting":{"reason":"PodInitializing"}}                 restarts=0

The state of the blocking container tells you which branch you are in:

STATUS columnBlocking init container stateMeaningGo to
Init:N/M, restarts 0, for minutesrunningIt is hung or looping, not failingStep 2
Init:Error / Init:CrashLoopBackOffterminated / waiting: CrashLoopBackOffIt exits non-zeroStep 3
Init:OOMKilledterminated, exit code 137Memory limit too low for the init workStep 4
Init:ImagePullBackOff / Init:ErrImagePullwaitingThe init image cannot be pulledStep 5
Init:CreateContainerConfigErrorwaitingMissing Secret or ConfigMap referenceStep 5
Init:N/M with waiting: PodInitializing on the first onewaitingSandbox or volumes not readyStep 5
PodInitializing (no Init: prefix)all terminated, exit 0Init finished; app containers are startingNot an init problem

Step 2: The init container is Running forever

Zero restarts and a running state for ten minutes means the container is doing exactly what it was told: waiting. Nearly every case is a dependency wait loop like this one:

initContainers:
  - name: wait-for-db
    image: busybox:1.36
    command: ['sh', '-c', 'until nc -z postgres.data.svc.cluster.local 5432; do echo waiting for db; sleep 2; done']

Read what it is printing, then get a shell inside it. kubectl exec works on a running init container:

kubectl -n orders logs api-7c9d8b6f5-x2kqp -c wait-for-db --tail=5
kubectl -n orders exec -it api-7c9d8b6f5-x2kqp -c wait-for-db -- sh

From that shell, test the dependency in layers so you know which one is broken:

nslookup postgres.data.svc.cluster.local     # 1. does the name resolve?
nc -zv -w 3 postgres.data.svc.cluster.local 5432   # 2. does the port answer?
  • The name does not resolve. Either the Service does not exist in that namespace (kubectl -n data get svc postgres), the name is wrong (a short name like postgres only resolves inside the Service's own namespace), or cluster DNS is failing. If other names fail too, work through Kubernetes DNS resolution failures.
  • The name resolves, the port times out. A NetworkPolicy is dropping the traffic, or the Service has no ready endpoints. Check kubectl -n data get endpointslices -l kubernetes.io/service-name=postgres. An empty address list means the dependency itself is down or failing its readiness probe, and your pod is correctly waiting for it.
  • The port is refused instantly on every destination. That is the service mesh case below.

The service mesh trap

With Istio or Linkerd in classic sidecar mode, the proxy is an ordinary container, so it starts after all init containers. But the pod's iptables rules already redirect outbound TCP to the proxy's port. Your init container's connection goes to a proxy that does not exist yet and gets connection refused, forever. The tell is that it fails for every destination, including ones that work from a pod without the mesh.

Three fixes, best first:

  1. Native sidecars. On Kubernetes 1.29 and later, the mesh can inject its proxy as an init container with restartPolicy: Always, which starts before your init containers and keeps running. In Istio this is the ENABLE_NATIVE_SIDECARS pilot setting; check whether your version already enables it.
  2. Exclude the port from redirection for that workload:
metadata:
  annotations:
    traffic.sidecar.istio.io/excludeOutboundPorts: "5432"
    # Linkerd equivalent: config.linkerd.io/skip-outbound-ports: "5432"
  1. Run the init container as UID 1337 (Istio's proxy user), whose traffic is exempt from redirection. It works, but it bypasses mTLS and policy for that container, so treat it as a last resort.

Make the wait loop fail loudly

An unbounded until loop turns an outage in a dependency into a silent hang that no restart-based alert will catch. Bound it, so it becomes a visible Init:Error with a message:

command:
  - sh
  - -c
  - |
    timeout 120 sh -c 'until nc -z postgres.data.svc.cluster.local 5432; do sleep 2; done' \
      || { echo "postgres:5432 unreachable after 120s"; exit 1; }

Step 3: Init:Error and Init:CrashLoopBackOff

The container runs and exits non-zero. With the pod's restartPolicy set to Always or OnFailure, the kubelet retries it with a backoff that doubles from 10 seconds up to 5 minutes; that waiting period is what Init:CrashLoopBackOff shows. With restartPolicy: Never (typical for Jobs), one failure marks the whole pod Failed.

Get the exit code and the output of the attempt that failed. While the container sits in backoff, the current instance has no logs, so use --previous:

kubectl -n orders logs api-7c9d8b6f5-x2kqp -c run-migrations --previous
kubectl -n orders get pod api-7c9d8b6f5-x2kqp \
  -o jsonpath='{.status.initContainerStatuses[?(@.name=="run-migrations")].lastState.terminated}'
{"exitCode":127,"reason":"Error","startedAt":"2026-11-24T02:20:41Z","finishedAt":"2026-11-24T02:20:41Z"}
Exit codeMeaningUsual cause in an init container
1The program reported failureMigration error, bad credentials, chown: Operation not permitted
2Shell usage errorSyntax error in an inline sh -c script, often broken YAML quoting
126Found but not executableScript mounted from a ConfigMap without defaultMode: 0755
127Command not foundBinary missing from a slim or distroless image, or command and args mixed up
137SIGKILLOOM kill (Step 4)

Three failures show up far more often than the rest:

The permission-fixing init container. A chown -R 1000:1000 /data init container fails with Operation not permitted as soon as the namespace enforces non-root. Delete the init container and let the kubelet do it:

spec:
  securityContext:
    fsGroup: 1000
    fsGroupChangePolicy: OnRootMismatch

The migration init container. Running schema migrations in an init container means every replica runs them, at the same time, on every rollout. One replica takes the migration lock; the others wait on it or fail, and a migration that outlives the rollout's progressDeadlineSeconds marks the Deployment as failed while the ALTER is still running. Move migrations to a single pre-deploy Job (a Helm pre-upgrade hook or an Argo CD PreSync hook), and review them before they run, as in the schema migration review agent post.

Init containers are re-run. If the pod sandbox is recreated (node reboot, container runtime restart), every init container runs again from the first. A script that fails when its output already exists (mkdir without -p, git clone into a non-empty emptyDir that survived) passes on first start and crash-loops on the second. Make every init step idempotent.

If the output is an ordinary application stack trace, the method from here is identical to an app container; see CrashLoopBackOff.

Step 4: Init:OOMKilled

Exit code 137 with reason OOMKilled means the init container hit its own memory limit. Init containers have their own resources block and are commonly given a token 64Mi while doing heavy work: unpacking an archive, downloading a model, running a migration tool on a JVM.

kubectl -n orders get pod api-7c9d8b6f5-x2kqp \
  -o jsonpath='{range .spec.initContainers[*]}{.name}{"\t"}{.resources}{"\n"}{end}'

Raising the limit is cheaper than it looks. Init containers do not run alongside the app containers, so the scheduler does not add them up. The pod's effective request is the larger of the biggest single init container request and the sum of all app container requests. An init container requesting 1Gi in a pod whose app containers total 2Gi costs nothing extra. The reverse is the trap: an init container requesting 8Gi makes a 512Mi pod reserve 8Gi on its node for its whole life, and can leave it stuck in Pending instead of Init:. Native sidecars are the exception: they keep running, so their requests are added to the app containers' total. The general diagnosis is in OOMKilled (exit code 137).

Step 5: The init container never starts

When the blocking init container is waiting rather than running or terminated, it is hitting the same pre-start failures as any container, just with an Init: prefix on the status. The events name the cause:

kubectl -n orders describe pod api-7c9d8b6f5-x2kqp | sed -n '/Events/,$p'
  • Init:ImagePullBackOff: init images are often pulled from a different registry than the app (a public busybox, a vendor's tooling image) and hit rate limits or missing pull secrets the app image never needs. See ImagePullBackOff.
  • Init:CreateContainerConfigError: the init container references a Secret or ConfigMap key that does not exist. See CreateContainerConfigError.
  • Init:0/N with FailedMount or FailedCreatePodSandBox events: the pod's volumes or network were never set up, so no container of any kind can start. This is not an init container problem; follow FailedMount and FailedAttachVolume.

One case is specific to native sidecars. An init container with restartPolicy: Always does not need to exit, but the next init container only starts once the sidecar has started, and if it defines a startupProbe, once that probe passes. A sidecar with a startup probe that can never succeed holds the pod at Init:N/M with the sidecar happily running. Check the probe before you blame the container after it.

Prevention

  • Bound every wait. No until loop without a timeout. A hang is invisible; a failure is alertable.
  • Prefer readiness over ordering. An init container that waits for a database only protects the first start. The database can still vanish five minutes later, so the app needs retry logic and a real readiness probe anyway (see the probes guide). Once it has those, the wait-for init container is usually redundant.
  • Alert on both failure shapes. kube-state-metrics exposes init container state separately from app containers, and most stock alert rules only watch the latter:
- alert: InitContainerCrashLooping
  expr: kube_pod_init_container_status_waiting_reason{reason="CrashLoopBackOff"} == 1
  for: 10m
  labels:
    severity: warning
  annotations:
    summary: "Init container {{ $labels.container }} in {{ $labels.namespace }}/{{ $labels.pod }} is crash-looping"
- alert: PodStuckInitializing
  expr: |
    max by (namespace, pod) (kube_pod_status_phase{phase="Pending"}) == 1
    and on (namespace, pod)
    max by (namespace, pod) (kube_pod_init_container_status_running) == 1
  for: 20m
  labels:
    severity: warning
  annotations:
    summary: "Pod {{ $labels.namespace }}/{{ $labels.pod }} has had an init container running for 20 minutes"

The second rule catches the silent hang from Step 2. A pod stays in phase Pending until its init containers finish, so the Pending condition keeps healthy pods with long-lived native sidecars out of the result.

Quick reference

# 1. Which init container is blocking, and in what state?
kubectl -n NS get pod POD -o jsonpath='{range .status.initContainerStatuses[*]}{.name}{"\t"}{.state}{"\n"}{end}'
# 2. Running forever: read its output, then test the dependency from inside it
kubectl -n NS logs POD -c INIT --tail=20
kubectl -n NS exec -it POD -c INIT -- sh
# 3. Failing: logs and exit code of the last attempt
kubectl -n NS logs POD -c INIT --previous
kubectl -n NS get pod POD -o jsonpath='{.status.initContainerStatuses[?(@.name=="INIT")].lastState.terminated}'
# 4. OOMKilled: what limits do the init containers have?
kubectl -n NS get pod POD -o jsonpath='{range .spec.initContainers[*]}{.name}{"\t"}{.resources}{"\n"}{end}'
# 5. Never started: the events say why
kubectl -n NS describe pod POD | sed -n '/Events/,$p'

An Init: status narrows the problem more than any other pod state: the application has not run, so it cannot be the application. One named init container is either waiting on something, exiting with a code, or unable to start, and -c with its name gets you the answer.

#kubernetes#sre#devops#containers#reliability#incident-response
D
DevToCashAuthor

Senior DevOps/SRE Engineer · 10+ years · Professional Trader (IDX, Crypto, US Equities)

I write about real infrastructure patterns and trading strategies I use in production and in live markets. No courses, no affiliate hype — just documentation of what actually works.

More about me →