Fix pods that won't start
In this task you'll find out why a pod won't start, from its status, events and logs.
Most broken pods show a reason in kubectl get pods. ImagePullBackOff / ErrImagePull: the image name or tag is wrong, or the node can't sign in to the registry. CreateContainerConfigError: a ConfigMap, Secret or key the pod refers to doesn't exist. CreateContainerError and RunContainerError: the runtime couldn't create or start the container, for example a command that isn't in the image or a bad mount.
CrashLoopBackOff means the container starts, then exits, again and again, with longer and longer waits (up to 5 minutes). Read what the crashed run printed: while the pod waits to restart, plain kubectl logs shows that run; once it's running again, add --previous. OOMKilled means it used more memory than its limit, so the kernel killed it (exit code 137). Always use the same order: get, describe (events), logs --previous.
Example. Tollmere Logistics' tracking API showed CreateContainerConfigError after a release. kubectl describe said: couldn't find key DB_HOST in ConfigMap tracking-config. The new release renamed the key; the ConfigMap still had the old name.
Before you start
You need: Docker Desktop and kind on your computer (both free). Time: 40 minutes.
Where to look
- Terminal
- kubectl
Steps
- Break it on purpose: create a deployment with image
nginx:does-not-exist, and see ImagePullBackOff inkubectl get pods. - Break it another way: refer to a key that's missing in a ConfigMap (
configMapKeyRef), and read the CreateContainerConfigError message withkubectl describe pod. - Make it crash: use
busyboxwith the commandsh -c 'echo starting; exit 1', then runkubectl logs <pod>(and--previousif it has started again).The kubelet keeps only one stopped run, so--previouscan fail while the pod is waiting. - Make it run out of memory: set a 20Mi limit and run a memory hog, then find
OOMKilledand exit code 137 inkubectl describe. - For each one, write down the one line that told you the cause.
Commands
kubectl get pods
kubectl describe pod <pod> | sed -n '/State:/,/Ready:/p;/Events:/,$p'
kubectl logs <pod> --previous
kubectl get pod <pod> -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}'
Watch out for
- Cost
- Free on kind.
- Security
- Don't print Secret values while debugging;
kubectl describeshows only their key names, which is all you need. - Common mistakes
- Restarting or deleting the pod before reading
--previouslogs and events, which throws the evidence away.
Clean up
Delete the broken deployments.
Words to know
- CrashLoopBackOff
- The container keeps exiting after it starts, and Kubernetes waits longer between each restart.
- OOMKilled
- The container used more memory than its limit, so the kernel killed it (exit code 137).
- CreateContainerConfigError
- The pod refers to a ConfigMap, Secret or key that doesn't exist.
- ImagePullBackOff
- The node can't pull the image, because of a wrong name or tag or missing registry access, and is backing off.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands OnKeep going
- Kubernetes errors, decodedExplained
- AI agents for Kubernetes: how they work, how to keep them safeExplained
- Observing Kubernetes: events, logs, metrics and tracesExplained
- Read a pod.yaml and follow a pod's lifecyclePrevious in Kubernetes in depth
- Fix NotReady nodes and disk pressureNext in Kubernetes in depth
- Containers and KubernetesAll pages in this topic