Kubernetes OOMKilled: Diagnose Memory Limits and Node Pressure
Diagnose Kubernetes OOMKilled with previous container state, requests and limits, node pressure, logs and memory history. Includes a Pod JSON inspection helper.
Capture the terminated container’s reason, timestamps and effective memory settings before restarting or replacing the Pod. OOMKilled is different from a generic restart or node-pressure eviction. Correlate container, node and workload evidence, then change the memory budget or application behavior and verify the original workload.
The restart counter is a symptom, not the diagnosis
A worker restarts during a large import. The replacement process looks healthy, kubectl top shows modest memory use, and someone proposes doubling every limit. The missing evidence is what happened to the previous process and whether the node itself was under pressure.
Treat OOMKilled, CrashLoopBackOff and an evicted Pod as different observations. OOMKilled is a reported termination reason. CrashLoopBackOff describes delayed restart attempts after failures and does not identify their original cause. Node-pressure eviction is a kubelet decision to reclaim resources and can end the Pod rather than merely restart one container.
This guide focuses on Linux containers with container-level resource settings. Inspect your cluster version, runtime and actual Pod specification; admission policies and newer Pod-level features can change the surrounding configuration. No Kubernetes client, container runtime or cluster was available during preparation. The Kubernetes commands and configuration fragment are documentation-reviewed; the Python helper was tested locally with synthetic Pod JSON, not a real OOM event.
Preserve the old container’s evidence while it is available
Use the exact namespace, Pod and container names from the incident. Record the Pod UID, node name, deployment revision and time window. A controller can replace a Pod with another object, and a new object’s restart count is not the history of the removed one. Avoid deleting the failing Pod before collecting evidence unless recovery requirements force that tradeoff.
Inspect both state.terminated and lastState.terminated in the relevant container status. A restarted container may currently be running while its previous termination remains recorded. Check init-container statuses too, because startup failure may occur before the main worker begins.
Exit code 137 is consistent with a process receiving SIGKILL in common Linux conventions; it is not sufficient by itself to prove an out-of-memory cause. Use the reported reason, runtime and node evidence together. A low memory reading after the restart does not describe the process that was killed.
Saved Pod specifications and logs can contain environment values, application payloads and internal endpoints. Restrict the evidence files and redact them before sharing. The local helper prints only selected identity and termination fields; it does not sanitize the original pod.json file or establish that every other diagnostic artifact is safe to publish.
# Replace these example names with the affected workload.
kubectl get pod report-worker-abc -n reports -o json > pod.json
kubectl describe pod report-worker-abc -n reports
kubectl logs report-worker-abc -n reports -c worker --previous --timestamps
kubectl get events -n reports --field-selector involvedObject.name=report-worker-abc --sort-by=.metadata.creationTimestamp
# Read the node name from the saved Pod, then inspect that node.
kubectl describe node worker-node-aSource: Kubernetes: debugging running Pods and previous logs ↗
Summarize termination fields without guessing the cause
Save this as pod_termination.py and run python pod_termination.py < pod.json. It reads a single kubectl Pod JSON object and opens no network connection. A null termination field means that field is absent in the supplied snapshot; it does not prove that the container has never failed.
The output keeps current and previous termination separate and includes the Pod-level reason. The helper deliberately does not label every exit 137 as OOMKilled, infer missing restart counts, or combine histories across Pod UIDs. Use it as an inspection aid, then return to the saved specification, logs and monitoring.
import json
import sys
def summarize(pod):
if not isinstance(pod, dict) or pod.get("kind") != "Pod":
raise ValueError("Expected one Pod object, not a list")
metadata = pod.get("metadata") or {}
status = pod.get("status") or {}
rows = []
for group in ("initContainerStatuses", "containerStatuses"):
for container in status.get(group) or []:
current = (container.get("state") or {}).get("terminated") or {}
previous = (container.get("lastState") or {}).get("terminated") or {}
rows.append({
"group": group,
"container": container.get("name"),
"restarts": container.get("restartCount"),
"current_reason": current.get("reason"),
"current_exit_code": current.get("exitCode"),
"previous_reason": previous.get("reason"),
"previous_exit_code": previous.get("exitCode"),
"previous_finished_at": previous.get("finishedAt"),
})
return {"namespace": metadata.get("namespace"),
"pod": metadata.get("name"), "uid": metadata.get("uid"),
"phase": status.get("phase"), "pod_reason": status.get("reason"),
"containers": rows}
if __name__ == "__main__":
try:
print(json.dumps(summarize(json.load(sys.stdin)), indent=2))
except (ValueError, TypeError, AttributeError) as exc:
raise SystemExit("Cannot summarize Pod JSON: " + str(exc))
Requests, limits and memory units answer different questions
The scheduler uses resource requests when deciding whether a Pod fits on a node. A memory request is not the container’s maximum consumption. A container can use more than its request when resources are available, so scheduling success alone does not establish that concurrent workload peaks are safe.
A memory limit constrains the container’s memory budget through the runtime and kernel. Memory enforcement can result in OOM kills; it is not the same mechanism as CPU throttling. A configured limit is also not a promise that allocation stops cleanly at an exact application-visible byte boundary.
Inspect the effective Pod, not just the Deployment YAML in source control. Defaulting and admission policies can supply values. In particular, when a memory limit is specified without a request and no admission mechanism provided one, Kubernetes can use the limit as the request. A later increase may therefore affect placement as well as runtime behavior.
The fragment below belongs under one existing container’s resources field. It is an illustrative budget, not a full manifest or a sizing recommendation. 128Mi is 134217728 bytes and 256Mi is 268435456 bytes. Memory suffixes matter: 400m denotes a fraction of a byte, not 400 MiB; decimal M and binary Mi also differ.
# Fragment for one container; adapt to measured workload requirements.
resources:
requests:
cpu: "250m"
memory: "128Mi"
limits:
cpu: "1"
memory: "256Mi"Separate a container budget problem from node pressure
An OOM termination can require investigation at the container cgroup or node level. Look for evidence of the exhausted budget rather than assuming every OOMKilled reason proves that only this container’s configured limit was too small. Ask the node administrator for the corresponding kernel or runtime OOM record when the available Pod events do not establish the scope.
Node-pressure eviction is a separate path. Inspect the Pod phase and reason, node conditions, eviction messages and workloads sharing that node. MemoryPressure being false now does not rule out pressure during the incident. A rapid spike may also trigger kernel OOM handling before periodic observation leads to a pressure response.
Quality-of-service classes influence resource-related behavior but are not a guarantee against OOM or all eviction. Changing a workload to look Guaranteed is not a substitute for sufficient capacity and correct application memory use. Keep node reservations, other Pods and rollout overlap in the capacity discussion.
| Evidence | What to investigate next |
|---|---|
| Previous reason OOMKilled | Container budget, node/runtime OOM evidence and workload peak |
| Exit 137 with no OOM reason | Other SIGKILL causes, shutdown and runtime records |
| Pod reason Evicted with memory-related message | Node pressure, eviction conditions and node capacity |
| Pod Pending after increasing requests | Scheduler events and available requested capacity |
| New Pod has restartCount zero | Old Pod UID and retained monitoring/log history |
| No previous logs available | Log retention and centralized collection; absence is not proof of success |
Source: Kubernetes: node-pressure eviction and OOM handling ↗
Measure the workload that creates the peak
kubectl top depends on the Metrics Server path and supplies recent resource metrics, not a complete history of the killed process. Collect it when available, but use retained monitoring around the termination timestamp to investigate short peaks. Record the sampling interval and what the metric measures before comparing it with the limit.
Exercise the conditions that matter: cold startup, larger inputs, concurrent requests, cache warm-up and overlapping jobs. Distinguish a steady rise across repeated work from a temporary allocation burst. A memory leak, unbounded concurrency and an oversized input may all reach the same limit but require different repairs.
Application heap measurements may omit native allocations, stacks, runtime metadata or other container memory. Memory-backed emptyDir data can also contribute to memory use. Garbage collection of language objects does not automatically remove files that an application wrote to a memory-backed volume. Inspect those volumes and their lifecycle alongside the process.
# Requires working cluster metrics; values are recent observations.
kubectl top pod report-worker-abc -n reports --containers
kubectl top node worker-node-a
# Save the admitted Pod specification and resource values for comparison.
kubectl get pod report-worker-abc -n reports -o yaml > pod-observed.yamlUse a falsifiable hypothesis for a failing import
Consider a hypothetical importer that restarts only when several large files arrive together. Its previous status says OOMKilled, but a single small file succeeds. First capture the failed invocation’s time and input characteristics, then compare concurrent-job counts and retained memory measurements. Do not describe this pattern as a confirmed leak until the trend supports that conclusion.
A useful hypothesis is that each job buffers an entire file and several buffers coexist. A controlled test could bound concurrency while keeping representative file sizes, then compare peak memory and completion behavior. Streaming input or reducing batch size may fix the pressure without increasing the footprint of every replica.
If a larger memory budget is justified, verify node capacity, scheduling and the rollout path before applying it. The same limit increase across many replicas changes the possible aggregate load. Keep recovery reversible and change one meaningful variable at a time so the result can support or reject the hypothesis. This is a diagnostic example, not an experiment performed for this article.
Review the capacity consequence before raising a limit
Write down the change separately for one container and for the whole rollout. If ten worker replicas can each grow much larger after a limit increase, the node fleet must tolerate the corresponding workload behavior. A higher limit without a higher request may permit more overcommit than the team intended; increasing both may instead leave new Pods unschedulable.
Include temporary overlap during deployments, other containers in the Pod and nonapplication memory on the node. A capacity review is not just the sum of the workers currently visible in one namespace. Have the node administrator check allocatable capacity and reservations, and have the application owner explain which concurrency or input conditions can reach the new budget.
Choose an acceptance check before applying the change: the formerly failing workload must complete, its output must be correct, and memory behavior must remain bounded over repeated runs. Keep a rollback path and a representative baseline. This makes a successful recovery distinguishable from moving the same failure to a different node or a later request.
Verify completed work and a stable memory envelope
After a repair, replay a representative workload and observe it across startup, steady work and the previously failing peak. Track successful output, retries, restart counts and memory history. A Pod briefly returning Running does not establish that the import completed or that the next large request will fit.
Use the linked probe guide if health-check failures also appear in the evidence. Readiness, liveness and startup probes answer different questions from memory enforcement. Relaxing a probe cannot repair a container that is being OOM-killed, while a poorly chosen liveness check can create additional restarts that confuse the diagnosis.
Close the incident with the affected Pod UID, the scope of the memory failure, the effective resource configuration, the verified workload change and its observed result. Preserve evidence before and after the change. The goal is a repeatable workload within an understood memory budget, with enough node capacity to support its real concurrency.
Your next steps
- Capture previous container state, Pod UID and logs before replacing the evidence.
- Separate memory requests, container limits, node pressure and recent metric samples.
- Validate representative work and peak behavior after changing application or capacity settings.
Sources & official resources
Linked resources checked on 2026-10-27. Technical behavior and provider guidance can change; check the documentation for the version you use.
- Kubernetes: resource management for containers ↗
- Kubernetes: assigning and exceeding memory resources ↗
- Kubernetes: node-pressure eviction and OOM handling ↗
- Kubernetes: debugging running Pods and previous logs ↗
- Kubernetes: Pod lifecycle and container states ↗
- Kubernetes: kubectl top and metrics prerequisites ↗
- Kubernetes: Pod quality of service ↗
About this guide and its recommendations
Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.
Suggest a correction →