Interview Prep/Kubernetes/Pod startup failures

A Deployment's Pods keep going `Completed` then `CrashLoopBackOff`, with exit code 0 and no errors in logs.

BeginnerTroubleshootingPod startup failures
Answer

Likely causes → The process exits successfully. A Deployment requires restartPolicy: Always, so a container that finishes (a script, a one-shot task, a server that daemonises into the background) is restarted forever.

Diagnose →

kubectl get pod worker-x -o jsonpath='{.status.containerStatuses[0].lastState.terminated}'
kubectl logs worker-x --previous | tail

Fix → If it is a batch task, use a Job or CronJob. If it is a server, run it in the foreground (nginx -g 'daemon off;', exec java ... instead of java ... &).

Prevent → Long-running processes must be PID 1 in the foreground; review Dockerfile CMD in code review.

All Kubernetes questions Roadmap: Kubernetes core

More on Pod startup failures