Debugging Kubernetes: CrashLoopBackOff, ImagePullBackOff, Pending and OOMKilled
A runbook for the four pod states you will meet first, each one broken on purpose on a kind cluster: kubectl describe, logs --previous, events, lastState and an ephemeral debug container for a distroless image.
Most Kubernetes trouble shows up as one word in the STATUS column of kubectl get pods. CrashLoopBackOff, ImagePullBackOff, Pending, OOMKilled. The word tells you which part failed, and each one has a different place to look.
In this blog we will break shorty four ways on purpose on a local kind cluster, and for each one go through the commands that show what went wrong and how to fix it. Level is beginner. You should have the cluster from the first Kubernetes post with Postgres running, and it helps to have read the one on probes and limits. I used kind v0.33.0, Kubernetes v1.37.0 and kubectl v1.37.2. Every output below is copied from that cluster.
The runbook
Whatever the status, I go through these in order. Most of the time step 2 already have the answer.
kubectl get pods -o wide # 1. which pod, which status, how many restarts
kubectl describe pod <pod> # 2. State, Last State, and Events at the bottom
kubectl logs <pod> # 3. what the app printed
kubectl logs <pod> --previous # what the last crashed container printed
kubectl get events --sort-by=.lastTimestamp # 4. everything recent in the namespace
kubectl get events --field-selector type=Warning
I put all the broken Deployments in their own namespace so they are easy to throw away:
kubectl create ns debug
CrashLoopBackOff: the app starts and exits
This one I broke with a typo. The Service is called postgres, the URL says postgress:
apiVersion: apps/v1
kind: Deployment
metadata:
name: shorty-crash
spec:
replicas: 1
selector:
matchLabels:
app: shorty-crash
template:
metadata:
labels:
app: shorty-crash
spec:
containers:
- name: shorty
image: shorty:v2
env:
- name: DATABASE_URL
# typo on purpose: the Service is called postgres
value: postgres://shorty:shorty@postgress:5432/shorty?sslmode=disable
kubectl -n debug apply -f crashloop.yaml
kubectl -n debug get pods -w
NAME READY STATUS RESTARTS AGE
shorty-crash-55f9d6f6d-qjhhc 0/1 Error 4 (117s ago) 2m39s
shorty-crash-55f9d6f6d-qjhhc 0/1 CrashLoopBackOff 4 (75s ago) 2m46s
shorty-crash-55f9d6f6d-qjhhc 1/1 Running 5 (83s ago) 2m54s
shorty-crash-55f9d6f6d-qjhhc 0/1 Error 5 (84s ago) 2m55s
Notice the status flips between Error, CrashLoopBackOff and a one second Running. CrashLoopBackOff isn't the error itself. It means "this container keeps exiting, so I'm waiting longer before each restart". The real reason is in the logs only:
kubectl -n debug logs deploy/shorty-crash --previous
shorty: postgres ping: failed to connect to `user=shorty database=shorty`: hostname resolving error: lookup postgress on 10.96.0.10:53: no such host
A small gotcha I hit here. My first few --previous calls failed with unable to retrieve container logs for containerd://.... A minute later the same command worked. And while the container is down, plain kubectl logs (without --previous) already shows the output of the last crash, so try both. describe also gives the exit code under Last State: here Exit Code: 1, which is shorty's own os.Exit(1). 137 would be a kill, which is a different story (see OOMKilled below).
It's a good habit for apps to print one clear line before exiting, like shorty does. Logs from an app that dies silently are much less fun.
The fix:
kubectl -n debug set env deploy/shorty-crash \
DATABASE_URL='postgres://shorty:shorty@postgres.default.svc:5432/shorty?sslmode=disable'
The full name postgres.default.svc is needed because this pod is in the debug namespace and Postgres is in default.
ImagePullBackOff: the node can't get the image
containers:
- name: shorty
image: shorty:v3
There's no shorty:v3 anywhere. I never built it.
kubectl -n debug describe pod -l app=shorty-pull
Normal Pulling 18s (x4 over 100s) kubelet Pulling image "shorty:v3"
Warning Failed 17s (x4 over 98s) kubelet Failed to pull image "shorty:v3": failed to pull and unpack image "docker.io/library/shorty:v3": failed to resolve reference "docker.io/library/shorty:v3": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
Warning Failed 17s (x4 over 98s) kubelet Error: ErrImagePull
Normal BackOff 3s (x5 over 98s) kubelet Back-off pulling image "shorty:v3"
The message is the same for "this image doesn't exist" and "you aren't allowed to see it", which is quite annoying. My checklist for this one:
- The tag. Is it really pushed? A typo in the tag is the usual suspect.
- The registry. A name without a registry, like
shorty:v3, means Docker Hub (docker.io/library/...). - Credentials. A private registry needs
imagePullSecrets, or on EKS the node role needs ECR pull permission. - On kind, did you run
kind load docker-image? The node doesn't see your Docker images.
Fix is to point it at an image that exists, here kubectl -n debug set image deploy/shorty-pull shorty=shorty:v2.
A cousin: CreateContainerConfigError
While I was at it I also deployed a pod that reads DATABASE_URL from a Secret that doesn't exist in the namespace. The image pulls fine, but the container can't be created:
NAME READY STATUS RESTARTS AGE
shorty-nosecret 0/1 CreateContainerConfigError 0 8s
The event says it plainly: Error: secret "shorty-db" not found. Same for a missing ConfigMap or a wrong key.
Pending: no node can take the pod
resources:
requests:
cpu: "64"
memory: 64Mi
64 CPUs. My kind node has 10.
NAME READY STATUS RESTARTS AGE
shorty-pending-5b84fb8d6f-4tczl 0/1 Pending 0 65s
A Pending pod hasn't been placed on a node yet, so there are no logs at all. The scheduler explains itself in the events:
Warning FailedScheduling 0/1 nodes are available: 1 Insufficient cpu. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
To see how much room a node really has, look at Allocatable and Allocated resources in the node description:
kubectl describe node | grep -A8 -E "Allocatable:|Allocated resources:"
See, it's the requests that count here, not real usage. A node can be almost idle and still refuse pods because everything on it asked for a lot. Other reasons you'll see in the same event: taints the pod doesn't tolerate, a nodeSelector that no node matches, or a PersistentVolumeClaim that can't be bound. On a cluster with node autoscaling, Pending is often normal for a minute while a new node comes up.
Fix: kubectl -n debug set resources deploy/shorty-pending --requests=cpu=100m.
OOMKilled: over the memory limit
This is the one that's easy to miss, because the pod looks fine most of the time. I gave shorty a 6Mi limit. At idle it uses 3 to 4 MB, so it started and ran:
resources:
requests:
memory: 6Mi
limits:
memory: 6Mi
Then I sent 600 POST requests at it, 30 at a time, through port-forward:
kubectl -n debug port-forward deploy/shorty-oom 18082:8080 &
seq 1 600 | xargs -P 30 -I{} curl -s -o /dev/null -w '%{http_code}\n' \
-X POST localhost:18082/links -d '{"url":"https://example.com/{}"}' | sort | uniq -c
Every single one came back as 000, because the container died on the first burst and took the port-forward with it. A few seconds later:
NAME READY STATUS RESTARTS AGE
shorty-oom-cd74dccd6-r59rf 1/1 Running 1 (4s ago) 18s
Running, 1/1. If you only look at the status column, you'd say all good. The restart count is the hint, and describe has the proof:
State: Running
Started: Thu, 19 Nov 2026 13:14:44 +0530
Last State: Terminated
Reason: OOMKilled
Exit Code: 137
Exit code 137 is 128 + 9, killed by SIGKILL. The app gets no chance to log anything. logs --previous showed only the startup lines, no error, nothing:
{"time":"2026-11-19T07:44:31.196517231Z","level":"WARN","msg":"REDIS_URL not set, running without a cache"}
{"time":"2026-11-19T07:44:31.21772773Z","level":"INFO","msg":"listening","addr":":8080","version":"v2"}
There was no OOM event in kubectl get events either. Last State is where it shows up. So when a pod has restarts and clean logs, check Last State first. To find every OOMKilled container in a namespace:
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.containerStatuses[0].lastState.terminated.reason}{"\n"}{end}'
Fix is a limit that fits real usage plus headroom. I set 32Mi request and 64Mi limit, ran the same 600 requests and got 600 201. crictl stats on the node showed about 19 MB during the load. If the memory keeps growing at any limit, it's a leak and the limit just tells you sooner.
One more detail I noticed: this pod's QoS class was Burstable, even with memory request equal to limit, because there was no CPU request or limit. Guaranteed needs both.
Getting a shell into a distroless container
shorty's image is distroless, no shell at all, and kubectl exec says so:
OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH
An ephemeral debug container solves this. It adds a temporary container with your tools to the running pod, and --target puts it in the same process namespace as the app:
kubectl debug -it <pod> --image=busybox:1.37 --target=shorty --profile=general
From inside I ran:
/ # ps
PID USER TIME COMMAND
1 65532 0:00 /shorty serve
25 root 0:00 sh
35 root 0:00 ps
/ # wget -qO- localhost:8080/readyz
{"postgres":"ok","redis":"ok"}
/ # nslookup postgres.default.svc.cluster.local | tail -3
Address: 10.96.92.32
You can see shorty as PID 1 under uid 65532, call it on localhost, and test DNS from the pod's own network. /proc/1/root gives you its filesystem and /proc/1/environ its env vars, which is how I checked config values in the previous post. Mind that the debug container runs as root by default and stays in the pod spec until the pod is replaced. And kubectl prints a warning that everything typed into the session ends up in the container logs, credentials too.
Cleaning up
kubectl delete ns debug
That's the runbook. Status word first, then describe, then logs, then Last State, then a debug container if you still need to poke around.