Kubernetes Troubleshooting

Diagnose common Kubernetes failures step by step: CrashLoopBackOff, ImagePullBackOff, Pending Pods, OOMKilled and Services with no endpoints.

Most Kubernetes incidents can be solved by a repeatable routine: find the failing object, read its status and events, read the logs, and then check the layer around it. This lesson gives that routine and walks through the failures that interviewers ask about most.

The General Debugging Routine

Work from the outside in, and let Kubernetes tell you what it knows.

# 1. What is the state?
kubectl get pods -n production -o wide

# 2. Why is it in that state? Read Status, Conditions and Events at the bottom.
kubectl describe pod orders-7c9d8f6b5d-x2k4p -n production

# 3. What did the application say?
kubectl logs orders-7c9d8f6b5d-x2k4p -n production
kubectl logs orders-7c9d8f6b5d-x2k4p -n production --previous   # the crashed container

# 4. What else happened in the namespace?
kubectl get events -n production --sort-by=.lastTimestamp

# 5. Look inside the container
kubectl exec -it orders-7c9d8f6b5d-x2k4p -n production -- sh
Symptom First command What you are looking for
Pod not Running kubectl describe pod Events and Reason of the last state
Container restarting kubectl logs --previous Exception or exit code
Service unreachable kubectl get endpoints Empty endpoints list
Node trouble kubectl describe node Conditions and allocated resources

CrashLoopBackOff

The container starts, exits, and Kubernetes keeps restarting it with a growing delay (10s, 20s, 40s up to 5 minutes). The status is a symptom, not a cause.

Common causes: an application exception on startup, a missing environment variable or ConfigMap key, a wrong command or arguments, failing to connect to a database, a failing liveness probe that kills a healthy but slow container, or an OOM kill.

kubectl describe pod orders-7c9d8f6b5d-x2k4p | grep -A8 "Last State"
#     Last State:     Terminated
#       Reason:       Error
#       Exit Code:    1

kubectl logs orders-7c9d8f6b5d-x2k4p --previous

Exit code hints: 1 is an application error, 137 is SIGKILL (often OOMKilled), 143 is SIGTERM (graceful stop), and 127 means the command was not found.

ImagePullBackOff and ErrImagePull

Kubernetes cannot download the image.

kubectl describe pod orders-abc | grep -A6 Events
#   Warning  Failed  Failed to pull image "registry.example.com/orders:1.2.3":
#            rpc error: ... pull access denied / not found

Check these in order:

  1. The image name and tag are spelled correctly and the tag exists.
  2. The registry is reachable from the node.
  3. For a private registry, an imagePullSecret exists in the same namespace and is referenced by the Pod or ServiceAccount.
kubectl create secret docker-registry regcred \
  --docker-server=registry.example.com \
  --docker-username=ci --docker-password="$REGISTRY_TOKEN" \
  -n production

Pending Pods

A Pod stays Pending when the scheduler cannot place it, or when it is waiting for storage.

kubectl describe pod orders-abc | grep -A5 Events
#   Warning  FailedScheduling  0/3 nodes are available:
#            3 Insufficient memory.

Typical reasons:

Message Cause Fix
Insufficient cpu/memory Requests larger than free capacity Lower requests or add nodes
node(s) had untolerated taint Node taint with no matching toleration Add a toleration or use other nodes
didn't match Pod's node affinity/selector nodeSelector or affinity too strict Fix labels or the selector
unbound immediate PersistentVolumeClaims PVC has no matching PV or StorageClass Check kubectl get pvc and the StorageClass

OOMKilled

The container used more memory than its limit, and the kernel killed it.

kubectl describe pod orders-abc | grep -B2 -A6 "Last State"
#     Last State:     Terminated
#       Reason:       OOMKilled
#       Exit Code:    137

kubectl top pod orders-abc --containers

Raise the memory limit if the application genuinely needs more, or fix a leak. For Java, make the JVM respect the container limit, for example -XX:MaxRAMPercentage=75.0, because heap plus metaspace, threads and native memory must all fit in the limit.

Service Has No Endpoints

Requests to a Service fail even though the Pods are running. The usual cause is a selector that does not match the Pod labels, or Pods that are not Ready.

kubectl get svc orders -n production
kubectl get endpoints orders -n production
# NAME     ENDPOINTS   AGE
# orders   <none>      5m          <-- no Pods selected

kubectl get svc orders -n production -o jsonpath='{.spec.selector}'
kubectl get pods -n production --show-labels
kubectl get pods -n production -l app=orders

Check, in order:

  1. The Service selector exactly matches the Pod labels.
  2. The Pods are Ready (a failing readiness probe removes them from endpoints).
  3. targetPort matches the port the container actually listens on.
  4. A NetworkPolicy is not blocking traffic.

Test from inside the cluster to separate DNS, Service and application problems:

kubectl run tmp --rm -it --image=busybox:1.36 -- sh
# / # nslookup orders.production.svc.cluster.local
# / # wget -qO- http://orders.production:8080/actuator/health

Other Frequent Problems

Problem How to confirm Typical fix
CreateContainerConfigError describe pod shows a missing ConfigMap or Secret Create the object or fix the key name
Rollout stuck kubectl rollout status times out Fix the failing new Pods, then kubectl rollout undo
Node NotReady kubectl describe node conditions Check kubelet, disk, network on the node
Evicted Pods describe pod shows eviction due to DiskPressure Free disk, set ephemeral-storage limits
Ingress returns 404/502 Ingress controller logs, backend Service and port Fix host/path rules or the backend

Debugging Containers Without a Shell

Distroless and minimal images have no shell. Use an ephemeral debug container:

kubectl debug -it orders-abc --image=busybox:1.36 --target=orders

You can also copy the Pod with a different image or command using kubectl debug orders-abc --copy-to=orders-debug --container=orders -- sh.

Common Mistakes

  • Reading only kubectl get pods. The status line hides the reason, so always run describe and check the Events.
  • Forgetting --previous. After a restart, current logs are empty, and the crash is in the previous container's logs.
  • Restarting Pods without finding the cause. The problem returns, and the evidence is gone.
  • Debugging in production with changes. Edit nothing by hand; fix the manifest in Git and apply it.
  • Ignoring events expiry. Events are kept for about an hour, so capture them early.

Best Practices

  • Follow the same order every time: status, describe, logs, events, then deeper checks.
  • Add readiness and liveness probes so failures are visible and contained.
  • Keep centralized logs and metrics so you can investigate after a Pod is gone.
  • Set resource requests and limits so scheduling and OOM behaviour are predictable.
  • Keep a small debug image (busybox, netshoot) available for network checks.

Interview Questions

1. A Pod is in CrashLoopBackOff. How do you debug it?

Run kubectl describe pod to see the last state, exit code and events, then kubectl logs --previous to read the output of the crashed container. Common causes are application errors, bad configuration, failed dependencies, a too-aggressive liveness probe and OOM kills.

2. What is the difference between ImagePullBackOff and CrashLoopBackOff?

ImagePullBackOff means Kubernetes cannot download the image (wrong name or tag, no registry access, missing pull secret). CrashLoopBackOff means the image ran but the container keeps exiting.

3. A Pod stays Pending. What do you check?

Run kubectl describe pod and read the FailedScheduling event. Look for insufficient CPU or memory, taints without tolerations, node selector or affinity mismatches, and unbound PersistentVolumeClaims.

4. What does exit code 137 mean?

The process was killed with SIGKILL (128 + 9). In Kubernetes this is most often OOMKilled, where the container exceeded its memory limit, but it can also come from a forced kill after a grace period.

5. A Service returns connection errors even though Pods are Running. What do you check?

Check kubectl get endpoints for the Service. Empty endpoints mean the selector does not match the labels, or the Pods are not Ready. Then verify targetPort, readiness probes, DNS and any NetworkPolicy.

6. How do you debug a container that has no shell?

Use kubectl debug to attach an ephemeral container with debugging tools that shares the target container's namespaces, or create a debug copy of the Pod.

7. A rollout is stuck. How do you recover?

Check kubectl rollout status and the new Pods with describe and logs to find the failure. If the release is bad, run kubectl rollout undo deployment/<name> and fix the issue before retrying.

Summary

  • Troubleshoot with a fixed routine: get, describe, logs --previous, events, then exec.
  • Know the main failure states: CrashLoopBackOff, ImagePullBackOff, Pending, OOMKilled and empty Service endpoints.
  • Exit codes and events usually point straight at the cause.
  • Fix problems in version-controlled manifests rather than by hand.

Continue Learning

Previous: Kubernetes Monitoring | Next: Kubernetes Production Best Practices

Was this guide helpful?

CodeWithVenu is free to read, with no paywall. If this guide saved you time or helped you prepare, a small voluntary contribution helps me write more practical tutorials, architecture guides, and interview-prep content.