Diagnosing Kubernetes Pod failures and using kubectl debug
A 5-minute diagnostic order for Pending, ImagePullBackOff, CrashLoopBackOff, and OOMKilled(137) in Kubernetes, plus kubectl debug for distroless containers.
When a Kubernetes Pod stalls in
Pending,ImagePullBackOff,CrashLoopBackOff, orOOMKilled, guessing and redeploying wastes time. Here is a 5-minute diagnostic order (get pods→get events→describe→logs) pluskubectl debugfor shell-less distroless containers, verified on a localkindcluster.
All commands and outputs below were run on a local 2-node
kind+ Calico cluster (Kubernetesv1.37.0,kubectl v1.36.1,containerd://2.3.4) using public test images.
1. A 5-minute diagnostic order by failure stage
A Pod moves through three stages before reaching Running (READY 1/1): scheduling (node assignment) → image pull → container execution. Pinpointing which stage stalled immediately narrows down the command and fields to inspect.
flowchart TD
A["1. kubectl get pods -o wide"] --> B{"Node assigned?"}
B -->|"No (Pending)"| C["describe: FailedScheduling"]
B -->|"Yes (ImagePull)"| D["describe: Pull error"]
B -->|"Yes (Crash/OOM)"| E["describe Exit Code + logs"]
E -->|"No shell (distroless)"| F["kubectl debug --target"]
When multiple Pods fail at once, start with kubectl get pods -o wide and the chronological event stream (kubectl get events --sort-by='.lastTimestamp') before inspecting individual Pods.
| Status | Stalled stage | NODE assigned | Key describe fields | First command |
|---|---|---|---|---|
Pending | Scheduling | <none> | PodScheduled: False, FailedScheduling | kubectl describe pod |
ImagePullBackOff | Image pull | Yes | Waiting (ImagePullBackOff), Failed to pull image | kubectl describe pod |
CrashLoopBackOff | App startup/exit | Yes | Last State: Terminated, Reason: Error, Exit Code: 1 | kubectl logs --previous |
OOMKilled | Memory limit hit | Yes | Terminated, Reason: OOMKilled, Exit Code: 137 | kubectl describe pod |
In a dedicated lab-d4-debug namespace on the local kind cluster, I deployed all four fault Pods alongside a healthy distroless Pod and checked status at 22s and 38s:
1
kubectl get pods -n lab-d4-debug -o wide
1
2
3
4
5
6
7
8
9
10
# 22s after apply
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-crashloop 0/1 Error 2 (14s ago) 22s 192.168.25.134 k8s-lab2-worker <none> <none>
pod-distroless 1/1 Running 0 22s 192.168.25.136 k8s-lab2-worker <none> <none>
pod-imagepull 0/1 ImagePullBackOff 0 22s 192.168.25.133 k8s-lab2-worker <none> <none>
pod-oom 0/1 CrashLoopBackOff 1 (12s ago) 22s 192.168.25.135 k8s-lab2-worker <none> <none>
pod-pending 0/1 Pending 0 22s <none> <none> <none> <none>
# 38s after apply (right after pod-oom restarts)
pod-oom 0/1 OOMKilled 2 (28s ago) 38s 192.168.25.135 k8s-lab2-worker <none> <none>
Only pod-pending shows <none> for IP and NODE; the other four were scheduled onto k8s-lab2-worker. Sorting namespace events by timestamp puts every failure timeline on one screen:
1
kubectl get events -n lab-d4-debug --sort-by='.lastTimestamp'
1
2
3
4
5
6
7
8
9
LAST SEEN TYPE REASON OBJECT MESSAGE
38s Normal Scheduled pod/pod-oom Successfully assigned lab-d4-debug/pod-oom to k8s-lab2-worker
38s Warning FailedScheduling pod/pod-pending 0/2 nodes are available: 1 Insufficient cpu, 1 Insufficient memory, 1 node(s) had untolerated taint(s).
38s Normal Scheduled pod/pod-imagepull Successfully assigned lab-d4-debug/pod-imagepull to k8s-lab2-worker
36s Normal BackOff pod/pod-imagepull Back-off pulling image "nginx:nonexistent-tag-9999"
36s Warning Failed pod/pod-imagepull Error: ImagePullBackOff
16s Warning BackOff pod/pod-crashloop Back-off restarting failed container app in pod pod-crashloop_lab-d4-debug(...)
13s Warning BackOff pod/pod-oom Back-off restarting failed container worker in pod pod-oom_lab-d4-debug(...)
10s Warning Failed pod/pod-imagepull Failed to pull image "nginx:nonexistent-tag-9999": rpc error: code = NotFound ... docker.io/library/nginx:nonexistent-tag-9999: not found
2. Scheduling and image stages: Pending and ImagePullBackOff
Pending: never placed on a node
A Pending Pod hasn’t started any container yet, so kubectl logs returns nothing. Jump straight to kubectl describe pod and read the Conditions block and FailedScheduling event from default-scheduler.
Here is the describe output for pod-pending, which requests cpu: "64" and memory: "512Gi" on a 2-node local cluster:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Node: <none>
Status: Pending
Containers:
web:
Requests:
cpu: 64
memory: 512Gi
Conditions:
Type Status
PodScheduled False
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 38s default-scheduler 0/2 nodes are available: 1 Insufficient cpu, 1 Insufficient memory, 1 node(s) had untolerated taint(s). preemption: 0/2 nodes are available: 2 Preemption is not helpful for scheduling.
The message explains both nodes: one (control-plane) rejected the Pod due to an untolerated taint, and the single worker node lacked the requested CPU and memory.
As a related case not reproduced in this lab, a Pod also stays Pending when an unbound PersistentVolumeClaim or unmatched nodeSelector/affinity blocks scheduling. For PVC binding and storage design, see Kubernetes PV, PVC, StorageClass, and StatefulSets.
ImagePullBackOff: scheduled, but image fetch failed
ImagePullBackOff means scheduling succeeded (PodScheduled: True), but kubelet failed to pull the image through containerd and is now retrying with exponential backoff. The first failure appears as ErrImagePull, followed by ImagePullBackOff during the wait window.
Here is pod-imagepull referencing a non-existent tag (nginx:nonexistent-tag-9999):
1
2
3
4
5
6
7
8
9
10
11
12
13
Status: Pending
Containers:
web:
Image: nginx:nonexistent-tag-9999
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Events:
Normal Scheduled 38s default-scheduler Successfully assigned lab-d4-debug/pod-imagepull to k8s-lab2-worker
Warning Failed 36s kubelet spec.containers{web}: Error: ImagePullBackOff
Warning Failed 10s (x2 over 36s) kubelet spec.containers{web}: Failed to pull image "nginx:nonexistent-tag-9999": rpc error: code = NotFound desc = failed to pull and unpack image "docker.io/library/nginx:nonexistent-tag-9999": failed to resolve reference "docker.io/library/nginx:nonexistent-tag-9999": docker.io/library/nginx:nonexistent-tag-9999: not found
Warning Failed 10s (x2 over 36s) kubelet spec.containers{web}: Error: ErrImagePull
rpc error: code = NotFound points directly to a bad repository path or tag. This lab only tested a missing public tag on Docker Hub; for private registries (ECR, GCR, GHCR) with missing or expired imagePullSecrets, kubelet reports unauthorized or pull access denied instead of NotFound.
3. Runtime exit stage: CrashLoopBackOff and OOMKilled (137)
Once a container starts and exits repeatedly, kubelet backs off restarts under CrashLoopBackOff. Your first check is separating an application-level exit (Exit Code: 1, etc.) from a kernel OOM kill (Exit Code: 137).
CrashLoopBackOff: exit codes and previous logs
pod-crashloop checks for a required DATABASE_URL environment variable, writes an error to stderr, and exits with code 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
State: Terminated
Reason: Error
Exit Code: 1
Started: Sat, 05 Dec 2026 23:58:18 +0900
Finished: Sat, 05 Dec 2026 23:58:19 +0900
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Sat, 05 Dec 2026 23:58:04 +0900
Finished: Sat, 05 Dec 2026 23:58:05 +0900
Ready: False
Restart Count: 2
Events:
Warning BackOff 16s (x2 over 29s) kubelet spec.containers{app}: Back-off restarting failed container app in pod pod-crashloop_lab-d4-debug(...)
To read what the crashed instance printed before dying, pass --previous to kubectl logs. Using a verification Pod (pod-crashloop-check) that runs for 2 seconds before exiting, here is the difference right after its first restart (Running, RESTARTS 1):
1
2
kubectl logs pod-crashloop-check -n lab-d4-debug --previous
kubectl logs pod-crashloop-check -n lab-d4-debug
1
2
3
4
5
6
# Output with --previous (the terminated container)
[BOOT] 15:01:02 starting api-server...
[FATAL] 15:01:04 required env DATABASE_URL is missing
# Output without --previous (the newly started container)
[BOOT] 15:01:05 starting api-server...
Timing nuance between
kubectl logsandkubectl logs --previous
On Kubernetesv1.37.0withcontainerd://2.3.4,--previousreturned the terminated container’s logs as expected while the Pod was inState: RunningorWaiting (CrashLoopBackOff). However, when the current container itself was still inState: Terminated, plainkubectl logs <pod>returned the most recently terminated container’s logs, while--previousreached one container further back—whichcontainerdhad already garbage-collected—returningunable to retrieve container logs for containerd://.... Try--previousfirst, and if you seeunable to retrieve, runkubectl logs <pod>without the flag.
As an untested extension case for multi-container Pods (such as Pods with sidecars), omitting -c <container-name> causes kubectl logs to fail and ask for an explicit container name.
OOMKilled: Exit Code: 137 and cgroup memory limits
pod-oom runs python:3.12-alpine with limits.memory: 32Mi and allocates a 50 MiB bytearray. It initially appears as CrashLoopBackOff and then OOMKilled on restart, with describe recording Reason: OOMKilled and Exit Code: 137 (128 + SIGKILL 9):
1
2
3
4
5
6
7
8
9
10
11
State: Terminated
Reason: OOMKilled
Exit Code: 137
Last State: Terminated
Reason: OOMKilled
Exit Code: 137
Restart Count: 2
Limits:
memory: 32Mi
Requests:
memory: 16Mi
1
kubectl logs pod-oom -n lab-d4-debug
1
[WORKER] Allocating 50MiB inside 32Mi limit...
Because the Linux kernel kills the process immediately with SIGKILL, the application logs cut off without a stack trace. Whenever logs stop mid-execution, check Exit Code and Reason in describe.
Note that Exit Code: 137 reflects the Linux cgroup v2 kernel OOM killer. In an application-managed OOM case (not tested here)—such as a JVM hitting -Xmx and exiting with OutOfMemoryError—the process may exit with code 1 instead of 137. For memory limit sizing and probe-induced restarts, see Setting Docker container resource limits and handling JVM OOMKilled (137) and Configuring Kubernetes probes, resource limits, and preStop graceful shutdown.
4. Debugging shell-less distroless containers with kubectl debug
Production images built on gcr.io/distroless/* strip /bin/sh, ps, netstat, and curl to shrink attack surface. Running kubectl exec against pod-distroless (gcr.io/distroless/python3-debian12) fails immediately:
1
kubectl exec -n lab-d4-debug pod-distroless -- sh -c "ps aux"
1
error: Internal error occurred: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "...": OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH
Instead of rebuilding the image with debugging tools or restarting the Pod, attach an Ephemeral Container (kubectl debug, GA since Kubernetes 1.25). Passing --target=<container> shares the target container’s process and network namespaces:
1
2
3
4
kubectl debug -it -n lab-d4-debug pod-distroless \
--image=busybox:1.36 \
--target=app \
-- sh -c 'ps aux; netstat -tlnp; wget -qO- http://127.0.0.1:8080/ | head -n 8'
Attaching busybox:1.36 (debugger-mxpnl) to pod-distroless exposed the target process, listening socket, and local HTTP response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--- ps aux ---
PID USER TIME COMMAND
1 root 0:00 /usr/bin/python3.11 -m http.server 8080
17 root 0:00 sh -c ...
27 root 0:00 ps aux
--- netstat -tlnp ---
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1/python3.11
--- HTTP check to 127.0.0.1:8080 ---
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Directory listing for /</title>
</head>
Practical caveats and when not to use kubectl debug
- Retrieving output in non-interactive runs: In an interactive terminal,
-itstreams output directly. In a non-interactive shell or CI script (kubectl debug -i ... -- sh -c '...'), a short command can exit before the client attaches; its full stdout remains available viakubectl logs <pod> -c <debugger-name>. - When not to use
--targetin place: Ephemeral containers cannot be removed from a Pod spec once added (until the Pod is recreated), and--targetcan’t hold a stable process namespace if the target container is actively crash-looping. Production clusters may also restrictpods/ephemeralcontainersvia RBAC or Pod Security Admission. For crash-looping Pods, create a debug copy with a safe command instead (kubectl debug <pod> --copy-to=debug-pod --share-processes -- sleep 3600).
5. Reproducible manifest for a local kind cluster
You can reproduce all five scenarios locally with the manifest below (faults.yaml):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# faults.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-imagepull
namespace: lab-d4-debug
spec:
containers:
- name: web
image: nginx:nonexistent-tag-9999
---
apiVersion: v1
kind: Pod
metadata:
name: pod-pending
namespace: lab-d4-debug
spec:
containers:
- name: web
image: nginx:1.27-alpine
resources:
requests:
cpu: "64"
memory: "512Gi"
---
apiVersion: v1
kind: Pod
metadata:
name: pod-crashloop
namespace: lab-d4-debug
spec:
containers:
- name: app
image: busybox:1.36
command:
- sh
- -c
- |
echo "[BOOT] starting api-server..."
if [ -z "$DATABASE_URL" ]; then
echo "[FATAL] required env DATABASE_URL is missing" >&2
sleep 1
exit 1
fi
sleep 3600
---
apiVersion: v1
kind: Pod
metadata:
name: pod-oom
namespace: lab-d4-debug
spec:
containers:
- name: worker
image: python:3.12-alpine
command:
- python
- -c
- |
import time
print("[WORKER] Allocating 50MiB inside 32Mi limit...", flush=True)
buf = bytearray(50 * 1024 * 1024)
time.sleep(60)
resources:
requests:
memory: "16Mi"
limits:
memory: "32Mi"
---
apiVersion: v1
kind: Pod
metadata:
name: pod-distroless
namespace: lab-d4-debug
spec:
containers:
- name: app
image: gcr.io/distroless/python3-debian12
args: ["-m", "http.server", "8080"]
ports:
- containerPort: 8080
Apply inside an isolated namespace and delete the namespace when done:
1
2
3
4
5
6
kubectl create namespace lab-d4-debug
kubectl apply -f faults.yaml
kubectl wait --for=condition=Ready pod/pod-distroless -n lab-d4-debug --timeout=90s
# Clean up
kubectl delete namespace lab-d4-debug --timeout=90s
6. Production pitfalls and incident checklist
Event retention limit in production
Kubernetes retains Event objects in etcd for only 1 hour by default (--event-ttl=1h). OvernightFailedSchedulingorOOMKilledevents may be gone by morning, so ship cluster events to a persistent log pipeline or event exporter in production.
Walk through this five-step checklist before restarting or redeploying a failing workload:
- Classify the stage with
get pods -o wide: IfNODEis<none>, inspect scheduling (Pending); if a node is assigned, check image pull or runtime exit state. - Pull the timeline with
get events --sort-by='.lastTimestamp': Trace the earliestWarningevent first when several Pods fail together. - Confirm
ReasonandExit Codeindescribe pod: DistinguishFailedScheduling,NotFound/unauthorized,Exit Code: 1(app error), andExit Code: 137(OOMKilled). - Check both
logs --previousand plainlogs: If--previousreturnsunable to retrievewhile the container is inState: Terminated, runkubectl logs <pod>without the flag—and pass-c <container>for multi-container Pods. - Use
kubectl debug --targetfor distroless Pods: Whenkubectl execfails withexecutable file not found, attach an ephemeral container to inspect PIDs, sockets, and localhost endpoints, and readkubectl logs <pod> -c <debugger-name>after non-interactive runs.