McKube 0 requests sent

Init:CrashLoopBackOff & Failing InitContainers

Debug Pods stuck in Init:0/1 or Init:CrashLoopBackOff using targeted -c container log flags.

HIGH · Init:CrashLoopBackOff

Root Cause

Regular initContainers run sequentially before any app container starts. If an initContainer (such as a schema migration or vault-init step) exits non-zero, the Pod stays in Init:CrashLoopBackOff and main containers never launch.

Why It Happens

Running plain `kubectl logs <pod>` targets the first app container (which has never started) and returns an empty error. Always pass `-c <init-container-name>` plus `--previous` when restartCount > 0.

What It Looks Like in kubectl describe

Name:         api-3
Namespace:    shop
Status:       Init:CrashLoopBackOff
Init Containers:
  migrate:
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
    Restart Count:  3

How to Fix

  • Fetch the initContainer logs explicitly using `kubectl logs <pod> -n <ns> -c <init-name> --previous`.
  • Verify network policies allow egress from this Pod to the database or secret backend during init.
  • Ensure the initContainer is idempotent so retries after partial runs succeed cleanly.

Diagnostic Commands

kubectl logs <pod> -n <ns> -c <init-container> --previous --tail=150
kubectl describe pod <pod> -n <ns>