When a Pod misbehaves, the diagnostic path is short and consistent: get, describe, logs, exec, sometimes debug. This article is the runbook — what each command shows, the order to run them in, and the kubectl features (ephemeral debug containers, --previous, port-forward) that turn a stuck workload into a one-minute fix or a clear next step.
How to verify
The first thing you need to know is the Pod’s high-level state and recent events:
kubectl get pods -n team-payments -l app=web
kubectl describe pod web-7fdb6f9b56-2vp8x -n team-payments
kubectl get events -n team-payments --sort-by=.lastTimestamp | tail -20
The Pod’s status column tells you the failure class (CrashLoopBackOff, ImagePullBackOff, OOMKilled, Pending, ContainerCreating, Init:Error). describe shows the recent events for that Pod specifically — most diagnosis ends here.
For a richer view of the Pod’s spec and status:
kubectl get pod web-7fdb6f9b56-2vp8x -n team-payments -o yaml | yq '.status'
What’s happening
kubectl is a thin client over the Kubernetes API. Every debug command is a read against an object (get, describe) or a connection through the API server to the kubelet (logs, exec, port-forward, debug). The API server keeps the state; the kubelet on each node runs the containers and surfaces logs, terminal sessions, and ephemeral containers when asked. None of this requires SSH access to the nodes.
Distinct failure shapes need distinct tools:
- Pending Pod: the scheduler couldn’t place it.
describeshows0/4 nodes are available: insufficient cpuor a taint mismatch. No container exists, sologsis empty. - ContainerCreating / ImagePullBackOff: the kubelet is trying but failing — image pull error, missing Secret for the registry, image name typo.
describeevents show the pull error verbatim. - CrashLoopBackOff: the container started and exited.
logs --previousshows the last exit’s output; without--previousyou get the current attempt, which may not have started yet. - Running but broken:
execfor a shell,port-forwardto hit the app from your machine,logs -fto tail. - Distroless / scratch container: no shell to exec into.
kubectl debugattaches an ephemeral container sharing the Pod’s namespaces.
The procedure
-
Get and describe. This catches 80% of failures:
kubectl get pod web-7fdb6f9b56-2vp8x -n team-payments -o wide kubectl describe pod web-7fdb6f9b56-2vp8x -n team-paymentsThe Events section at the bottom of
describeis where most failures explain themselves. -
Logs, current and previous.
--previousis essential for CrashLoopBackOff Pods:kubectl logs web-7fdb6f9b56-2vp8x -n team-payments kubectl logs web-7fdb6f9b56-2vp8x -n team-payments --previous kubectl logs web-7fdb6f9b56-2vp8x -n team-payments -c init-db kubectl logs -f deploy/web -n team-payments --tail=200-ffollows;--taillimits initial output;-cselects a specific container in a multi-container Pod;--previousshows logs from the previous attempt. -
Exec into a running container for a shell — works when the image has
/bin/shor/bin/bash:kubectl exec -it web-7fdb6f9b56-2vp8x -n team-payments -- /bin/sh kubectl exec web-7fdb6f9b56-2vp8x -n team-payments -- env | sort -
Port-forward to talk to the Pod directly without going through the Service or ingress:
kubectl port-forward -n team-payments pod/web-7fdb6f9b56-2vp8x 8080:8080 # then from another terminal: curl -sv http://localhost:8080/healthz -
Attach an ephemeral debug container when the running container has no shell (distroless, scratch, hardened minimal image):
kubectl debug -n team-payments \ web-7fdb6f9b56-2vp8x \ -it --image=nicolaka/netshoot \ --target=webInside the debug container you share the target’s process and network namespaces —
ps,ss,curl localhostall work. -
Debug a node by running a privileged Pod that chroots into it — useful when you suspect the runtime, the kubelet, or kernel state:
kubectl debug node/ip-10-0-0-12 -it --image=ubuntu # inside: # chroot /host # systemctl status containerd # journalctl -u kubelet -n 100 -
Run an interactive copy of a Pod with overrides — useful for poking at a deploy with extra env vars or commands without modifying the real Pod:
kubectl debug -n team-payments \ web-7fdb6f9b56-2vp8x \ --copy-to=web-debug --container=web \ --image=registry.example.com/web:1.4.2 \ -- /bin/sh
Common pitfalls
kubectl logswithout--previouson a CrashLoopBackOff Pod returns nothing or partial output — the container died before producing logs in the current attempt;--previousis what you want.execrequires a shell in the image — distroless or scratch images have nothing to exec; usekubectl debug.kubectl debug --target=<container>only works ifprocess.shareProcessNamespaceis enabled or the runtime supports it (containerd does); without that, the debug container sees its own process tree.kubectl get pod -o yamlreturns the full object including managed fields and ConfigMap-projected volumes — pipe throughyq '.status'oryq '.spec'to narrow.- Events older than the etcd compaction window (default ~1 hour) are gone — diagnose recent failures fast or rely on a log aggregator.
We operate the kubectl debug workflow for clients with ephemeral containers enabled, distroless images everywhere, and runbooks that walk new engineers through describe → logs --previous → debug without surprises. See /en/services/managed-operations/.