When a Kubernetes cluster runs smoothly, you barely think about it. Deployments roll out, pods schedule, and traffic flows. Then one morning you get paged because a deployment is stuck, pods are flapping, and nothing in the logs makes immediate sense. In my experience, most Kubernetes troubleshooting panic comes not from the complexity of the platform itself, but from not having a systematic way to isolate where the failure lives. Is it the container? The pod spec? The network? The node? Learning to answer those questions in order is what turns a 2-hour outage into a 10-minute fix. This guide walks through the practical debugging workflow I use for the three most common failure categories I see in beginner and intermediate clusters: pod-level failures, networking issues, and resource-related problems. You do not need to be a Kubernetes expert to follow along, but you will need basic familiarity with kubectl and how pods and deployments work.
Diagnosing CrashLoopBackOff and ImagePull Failures at the Pod Level
CrashLoopBackOff is the error every newcomer meets first, and it is also the most misunderstood. It does not mean Kubernetes is broken. It means your container started, then exited with an error, then Kubernetes tried to restart it, it failed again, and the back-off timer is now increasing between restarts. The root cause is almost always inside the container or its configuration, not the cluster.
The first two commands I run are always the same. I check the pod status in detail to see the last termination reason, and then I pull the logs from the previous failed instance. Many beginners only run kubectl logs and see nothing because the current container has not yet written logs before crashing again.
# Get the detailed pod state, restarts, and last exit code
kubectl get pods -n production
kubectl describe pod api-deployment-7d9c8f6b4-2kq5z -n production
# Fetch logs from the last crashed instance, not just the current one
kubectl logs api-deployment-7d9c8f6b4-2kq5z -n production --previous
kubectl logs api-deployment-7d9c8f6b4-2kq5z -n production -c api-container
Inside kubectl describe pod, look closely at the State and Last State sections. An exit code of 1 usually means an application error, exit code 137 means the container was killed by OOM or a SIGKILL, and exit code 0 in a CrashLoopBackOff often means your entrypoint is finishing immediately because a script is missing an exec or a foreground process. I once spent an hour debugging a Node.js service that kept exiting with code 0 until I realized the Dockerfile was using CMD npm start & which backgrounded the process and let the container exit instantly.
Fixing ImagePullBackOff and ErrImagePull Without Guessing
If the pod never reaches a running state and shows ImagePullBackOff, Kubernetes could not download the container image. This is a registry, authentication, or naming problem. I've found that three things cover 90% of these cases: a typo in the image name or tag, a missing imagePullSecret for a private registry, or rate limiting from Docker Hub.
# Inspect the exact image error
kubectl describe pod api-deployment-7d9c8f6b4-2kq5z -n production | grep -A 10 "Failed"
# Verify the secret exists and is attached to the service account
kubectl get secrets -n production
kubectl get serviceaccount default -n production -o yaml
# Test the image locally to rule out a typo
docker pull ghcr.io/myorg/api:1.4.2
If you are using a private registry, make sure your imagePullSecrets is defined at the pod spec level, not just the deployment. And if you recently migrated to multi-stage builds, double-check that your final image tag was actually pushed. I recommend every team adopt consistent tagging and build hygiene as described in Dockerfile Best Practices: Multi-Stage Builds, Layer Caching and Security to avoid the classic "it worked locally but the tag doesn't exist in the registry" problem.
Handling Init Container and ConfigMap Mount Failures
Pods that hang in Init:0/1 or CreateContainerConfigError are often failing before your main application even starts. Init containers must complete successfully before the main containers start, so a failing init script will block the entire pod forever. Similarly, if you mount a ConfigMap or Secret as a volume and that object does not exist, the pod will never start. kubectl describe pod will show MountVolume.SetUp failed in the events. The fix is usually to create the missing ConfigMap or correct a typo in its name, but I always verify the mount path does not overwrite an essential directory in the container image.
Untangling Kubernetes Networking: DNS, Service Discovery and CNI Breakdowns
Networking issues are harder to debug than pod crashes because the pod can look perfectly healthy while traffic silently fails. In my experience, the failure pattern matters: if pod-to-pod communication works but service DNS does not, you likely have a CoreDNS problem. If DNS works but connections time out, you likely have a NetworkPolicy or kube-proxy/CNI issue.
Start by confirming whether the problem is DNS or connectivity. Exec into a temporary debug pod and try both IP and DNS resolution.
# Launch a temporary debugging pod with networking tools
kubectl run debug --rm -i --tty --image=nicolaka/netshoot -- /bin/bash
# Inside the debug pod, test DNS and direct connectivity
nslookup kubernetes.default
nslookup api-service.production.svc.cluster.local
getent hosts api-service.production.svc.cluster.local
curl -v http://api-service.production.svc.cluster.local:8080/healthz
curl -v http://10.96.45.12:8080/healthz # Try the ClusterIP directly
# Check if endpoints actually exist behind the service
kubectl get endpoints api-service -n production
kubectl get endpointslices -n production
If nslookup fails but direct IP works, CoreDNS is your culprit. Check the CoreDNS pods themselves: kubectl get pods -n kube-system -l k8s-app=kube-dns and then kubectl logs -n kube-system -l k8s-app=kube-dns. I have seen clusters where CoreDNS was under-provisioned and throttled due to low CPU limits, causing sporadic 5-second DNS timeouts that look random. Scaling CoreDNS from 2 to 4 replicas and removing overly restrictive CPU limits fixed it immediately.
If DNS succeeds but curl to the ClusterIP times out and kubectl get endpoints shows no endpoints, your service selector does not match any pods. This is a label mismatch, and it is extremely common after a Helm chart refactoring. Verify the service selector and pod labels match exactly. For a deeper dive into how services, DNS, and ingress interact, I often point newer engineers to Kubernetes Networking: Services, Ingress Controllers and Network Policies because understanding that full chain prevents a lot of guesswork.
When NetworkPolicies Silently Drop Traffic
NetworkPolicies are deny-by-default once you create one that selects a pod. In other words, if you apply a NetworkPolicy that selects your api pods but forget to allow ingress from your frontend or allow egress to your database, that traffic will be dropped with no log in your application. The connection will just time out. In my experience, this is the number one cause of "it worked before we added security policies" outages.
To confirm, list policies in the namespace and temporarily test without them in a staging environment. You can also use a CNI-aware tool like cilium connectivity test if you use Cilium, or simply create a policy that explicitly allows all traffic from your debug pod's labels to isolate the issue. Always document your intended allow-list before applying policies, and test them with both allowed and denied sources.
Resolving CPU and Memory Pressure: Resource Requests, Limits and OOMKilled Pods
Resource problems manifest in two distinct ways: pods that get killed unexpectedly (OOMKilled) and pods that never schedule or throttle heavily. Both stem from how you set requests and limits, which I still see misunderstood on many teams.
Requests control scheduling and CPU share. Limits control the maximum a container is allowed to use before being throttled (CPU) or killed (memory). If you set memory limits too low, the kernel OOM killer will terminate your container with exit code 137 and the pod will show reason OOMKilled. If you set CPU limits too low, you will not get an OOMKilled, but you will see severe latency and throttling that looks like an application performance bug.
# Find pods that were OOMKilled and check resource settings
kubectl get pods -n production --sort-by='.status.containerStatuses[0].restartCount'
kubectl describe pod api-deployment-7d9c8f6b4-2kq5z -n production | grep -A 5 "Last State"
kubectl top pods -n production
kubectl top nodes
# Example resource block that balances safety and efficiency
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "1000m"
I recommend starting without CPU limits for many workloads and only adding them if you have a noisy-neighbor problem. For memory, always set a limit that is higher than your request, and load-test to find the actual peak usage plus a 20-30% buffer. Use kubectl top and the metrics-server, or better yet, Prometheus and Grafana, to observe real usage over a week before tuning. If you are seeing throttling, container_cpu_cfs_throttled_seconds_total in Prometheus will confirm it quickly.
When nodes themselves are under pressure (MemoryPressure or DiskPressure), the kubelet will evict pods. Check node conditions with kubectl describe node. I have debugged clusters where log volumes filled the node disk because log rotation was not configured, causing the node to become NotReady and evict every pod on it. Cleaning up /var/log and adding a proper logrotate sidecar or centralized logging solved it permanently. For workloads that need to scale automatically based on these metrics, it is worth understanding decoupled scaling strategies like those in Kubernetes Autoscaling: HPA, VPA and KEDA for Event-Driven Scaling rather than manually guessing request values.
Debugging Persistent Scheduling Failures: Taints, Affinity and Insufficient Capacity
A pod stuck in Pending is a scheduling problem. Unlike CrashLoopBackOff, your container has not even been placed on a node yet, so logs will not help. The scheduler is telling you it cannot satisfy the constraints you set. kubectl describe pod will show a FailedScheduling event with a surprisingly precise reason if you read it carefully.
The most common causes I see are: insufficient CPU or memory in the cluster, a nodeSelector or affinity rule that matches no nodes, taints with no matching tolerations, and PersistentVolumeClaims that cannot be bound. For example, if you set nodeSelector: gpu: "true" but none of your nodes have that label, the pod will stay Pending forever. Similarly, if all nodes are tainted with dedicated=prod:NoSchedule and your pod lacks that toleration, it will never schedule.
# Diagnose scheduling failures
kubectl describe pod api-deployment-7d9c8f6b4-2kq5z -n production | grep -A 20 "Events"
kubectl get nodes --show-labels
kubectl describe nodes | grep -A 5 "Taints"
kubectl get pvc -n production
# Check actual allocatable resources vs. requested
kubectl describe node ip-10-0-12-45.ec2.internal | grep -A 10 "Allocated resources"
Capacity issues are straightforward but often missed in autoscaled clusters where the cluster autoscaler is disabled or misconfigured. If kubectl describe pod says 0/3 nodes are available: 3 Insufficient cpu, you need more nodes or smaller requests. If it says didn't match Pod's node affinity/selector, fix your labels. And if it says unbound immediate PersistentVolumeClaims, your storage class or volume provisioning has failed. According to the Kubernetes Documentation on scheduling and eviction, the scheduler will not attempt to place a pod if any of its required volumes cannot be provisioned, so always verify PVC status first when a stateful workload is stuck.
Inspecting Control Plane and Node Health When Pods Won't Start
Sometimes the problem is not your pod spec at all, but the health of the underlying node or control plane. I learned this the hard way when a whole node went NotReady after a kubelet upgrade, and I wasted 30 minutes debugging my deployment before I checked node status.
Make node health part of your initial triage. Run kubectl get nodes and look for anything other than Ready. A node in NotReady, MemoryPressure, or DiskPressure will affect every pod on it. kubectl describe node <node-name> will show conditions, recent events, and resource pressure details. Also check kubectl get componentstatuses or, on managed clusters, the cloud provider's control plane status page.
For managed Kubernetes like EKS or GKE, the control plane is usually stable, but worker node issues are common: kubelet stopped, container runtime (containerd) crashed, or the node's IAM role lost permission to pull images from ECR. On self-hosted clusters, also check etcd health and API server logs. A simple checklist I run through is: nodes Ready? kube-system pods healthy? CNI pods (like aws-node, calico-node, or cilium) running on every node? If the CNI daemonset has a pod crashing on one node, pods on that node will have networking failures even though they schedule.
Using kubectl Logs, Events and Ephemeral Containers for Live Debugging
When describe and logs are not enough, you need to look inside a running or failing container without changing its image. Kubernetes provides two powerful tools for this that beginners often overlook: sorted events and ephemeral debug containers.
Events are time-ordered warnings and actions that Kubernetes emits. They expire after about an hour by default, so they are the first thing to check after a failure.
# Get a cluster-wide view of recent warnings sorted by time
kubectl get events --sort-by='.lastTimestamp' -A | tail -n 50
kubectl get events -n production --field-selector type=Warning --sort-by='.lastTimestamp'
# Debug a running pod without ssh, using an ephemeral container (K8s 1.23+)
kubectl debug -it api-deployment-7d9c8f6b4-2kq5z -n production --image=busybox:1.35 --target=api-container
# Copy a file out of a pod for inspection
kubectl cp production/api-deployment-7d9c8f6b4-2kq5z:/var/log/app.log ./app.log
The kubectl debug pattern has replaced kubectl exec for many of my debugging workflows because it does not require your production image to contain a shell or debugging tools. It attaches a temporary container that shares the target container's process namespace and filesystem, so you can run ps, netstat, or inspect config files even if your main image is distroless. In my experience, pairing this with kubectl get events --sort-by gives you a timeline of what actually happened, not just the final failure state. The Kubernetes Documentation on debugging has excellent examples of this workflow that I recommend bookmarking.
| Command | What It Reveals | When To Use First |
|---|---|---|
kubectl describe pod <pod> |
Pod state, last exit code, events, scheduling failures, volume mount errors | Any pod that is Pending, CrashLoopBackOff, or ImagePullBackOff |
kubectl logs <pod> --previous |
Application stdout/stderr from the last crashed container instance | When describe shows exit code 1 or restarts > 0 |
kubectl get events --sort-by |
Time-ordered cluster warnings: FailedScheduling, FailedMount, Unhealthy, BackOff | When you need a timeline across multiple objects or namespaces |
kubectl exec / kubectl debug |
Live filesystem, processes, env vars, and network config inside the container | When logs are inconclusive and the container is running or needs introspection |
kubectl top pods / nodes |
Real CPU and memory usage vs. requests and limits | Suspected OOMKilled, throttling, or node pressure |
kubectl get endpoints / endpointslices |
Whether a Service has healthy backend pods attached | Service DNS resolves but connection times out or returns 503 |
One final habit that saves hours: always reproduce in a non-production namespace with the same manifests and a minimal workload. If the minimal pod runs, you have narrowed the problem to your config or load. If it also fails, you have likely found a cluster-wide issue. Consistent, repeatable debugging beats ad-hoc fixes every time, and it is how you build confidence operating Kubernetes in production.
Frequently Asked Questions
Why does my pod show CrashLoopBackOff even though the application works locally with Docker?
Local Docker runs often use different environment variables, secrets, and network settings than Kubernetes. In Kubernetes, your container may be missing a required ConfigMap, Secret, or environment variable, causing it to exit immediately. Check kubectl logs --previous for the actual error and compare kubectl describe pod against your local docker run flags. Also verify that your image's entrypoint runs a foreground process; a backgrounded command will make the container exit with code 0 and trigger a restart loop.
How do I tell the difference between an OOMKilled pod and a regular application crash?
Run kubectl describe pod <pod> and look at the Last State section. An OOMKilled pod will show Reason: OOMKilled and exit code 137. A regular crash will show exit code 1 or another application-specific code and may include a stack trace in kubectl logs --previous. Confirm with kubectl top pods and check if your memory limit is close to actual usage; if usage hits the limit, increase the limit or fix a memory leak in your application.
My service DNS name resolves but curl times out. What should I check?
If DNS resolves but connectivity fails, check whether the Service has endpoints: kubectl get endpoints <service>. If endpoints are empty, the Service selector does not match any pod labels. If endpoints exist but curl still times out, look for a NetworkPolicy that is blocking traffic or a misbehaving kube-proxy/CNI pod on the node. Executing a debug pod with kubectl run --rm -i --tty --image=nicolaka/netshoot and testing both ClusterIP and DNS helps isolate the layer that is failing.
What is the fastest way to get a timeline of what went wrong in my cluster?
Use kubectl get events --sort-by='.lastTimestamp' -A | grep Warning to get a chronological list of warnings across all namespaces. Filter by namespace with -n <namespace> and by time with --field-selector type=Warning. Events include FailedScheduling, FailedMount, Unhealthy probes, and BackOff messages. Since events expire after about an hour, check them soon after a failure occurs and consider shipping events to a log aggregator for longer retention.