Sub topic 14
Troubleshooting Pending, OOMKilled and evicted pods
This chapter assumes you know pods, deployments and namespaces, can apply YAML with kubectl, and have read the earlier chapters on requests, limits, QoS classes, node-pressure eviction, LimitRange and ResourceQuota. It gives a working method for the three most common resource failures.
Start with the pod's status
Run the same commands every time. They tell you which of the three problems you have.
kubectl top pod web
kubectl get pod web -o jsonpath='{.status.qosClass}'
kubectl get pod web -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}'
kubectl describe pod webkubectl top needs metrics-server. The describe output is the most useful part. Read the Events section at the bottom and the Last State block for each container.
| Symptom | Likely cause | Where to look |
|---|---|---|
| Pod stays `Pending` | No node has enough unreserved requests, or a quota blocks it | `Events` in `describe pod` |
| Container restarts, reason `OOMKilled`, exit code 137 | Memory use passed the container's limit | `Last State` in `describe pod` |
| Pod status `Failed`, reason `Evicted` | The node ran low on memory, disk or similar | `kubectl describe pod`, node conditions |
| Deployment has fewer pods than expected | A ResourceQuota rejected pod creation | Events on the ReplicaSet |
Diagnosing a Pending pod
The scheduler places a pod only on a node whose unreserved capacity covers the pod's requests. It compares requests, not live usage. A node can be nearly idle and still be "full" if other pods have requested most of it.
Look for a FailedScheduling event:
Warning FailedScheduling 0/3 nodes are available: 3 Insufficient memory.Common fixes:
- Lower the request if it is larger than the app needs.
- Add nodes or use larger nodes.
- Check that the request does not exceed the allocatable memory or CPU of your largest node. If it does, the pod can never schedule.
- Remove or shrink other workloads that over-request.
If no pod exists at all, the problem is earlier. A ResourceQuota can reject creation. The error appears on the ReplicaSet, not the pod, so run kubectl describe replicaset and kubectl describe resourcequota -n team-a to compare Used with Hard. A quota on requests or limits also rejects any pod that omits them, unless a LimitRange supplies defaults.
Diagnosing OOMKilled
When a container's memory passes its limit, the kernel kills the process. Kubernetes reports reason OOMKilled and exit code 137, then restarts the container according to the restart policy. Repeated kills lead to CrashLoopBackOff.
kubectl get pod web -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason}'If this prints OOMKilled, decide which case applies:
- Limit too low. Usage is steady and just above the limit. Raise the limit and the request.
- Memory leak. Usage climbs until each kill. Raising the limit only delays the restart. Fix the application.
- Spike at startup. Cache warm-up or a runtime that sizes itself from node memory. Set application memory settings, such as the JVM heap size, below the container limit.
Remember that CPU over the limit is throttled, not killed. A slow app with no restarts points to CPU limits, not memory.
Diagnosing evicted pods
Eviction is different from an OOM kill. The kubelet evicts pods when the node itself runs short of memory, disk or process IDs. The pod shows status Failed with reason Evicted, and its message names the resource.
The kubelet picks victims in order. Pods using more than their requests go first, and BestEffort pods are the first to qualify. Guaranteed pods are the last candidates. So a pod evicted repeatedly is usually BestEffort or Burstable with a request far below its real usage.
kubectl get pods --field-selector=status.phase=Failed
kubectl describe node worker-1In the node description, check Conditions for MemoryPressure or DiskPressure. Fixes are to set realistic requests, so the scheduler stops overpacking nodes, and to give critical workloads Guaranteed QoS. Evicted pods are not removed automatically in every case, so delete old ones with kubectl delete pod once you have read their messages.
Exercise
A pod is Pending. kubectl describe pod shows "0/3 nodes are available: 3 Insufficient cpu", yet kubectl top node shows every node at 20% CPU use. Why, and what do you change?
Show answer
The scheduler compares the pod's CPU request with each node's unreserved capacity, not with live usage. Other pods have requested most of the CPU on every node, even though they use little of it. Lower this pod's CPU request, reduce over-sized requests on other workloads, or add nodes.
Exercise
A container restarts every few minutes. The last terminated reason is OOMKilled and the exit code is 137. Memory climbs steadily between restarts. Is raising the limit the right fix?
Show answer
No. Steadily climbing memory suggests a leak, so a higher limit only delays the next kill. Find and fix the leak. Raise the limit only if usage is stable and sits just above the current limit.