Memory limits are hard limits. Here's how they bite, and how to size them.
What it means
The container used more memory than its resources.limits.memory. That limit is a cgroup limit, and when usage crosses it the kernel OOM killer sends SIGKILL to a process inside the container. The process gets no chance to clean up. Kubernetes records Reason: OOMKilled and exit code 137 (128 + 9), and the pod usually restarts, often into CrashLoopBackOff.
Two cases look similar but are different:
- Exit 137 without OOMKilled: something else sent SIGKILL, usually the kubelet after the termination grace period ran out.
- Evicted: the node itself was under memory pressure, so the kubelet removed pods, starting with those using the most above their requests.
Usual causes
- A real memory leak: usage climbs steadily, the pod is killed, restarts, repeats.
- The limit is too low for peak load, such as a large payload, a batch job or a cache warm-up.
- Runtime heap set equal to the limit: JVM
-Xmx, Node--max-old-space-size. Non-heap memory pushes the process over. - Many workers or threads, each with its own memory.
Debug commands
kubectl describe pod <pod> -n <ns> # Last State: Reason OOMKilled, Exit Code 137
kubectl get pod <pod> -n <ns> \
-o jsonpath='{.status.containerStatuses[*].lastState.terminated.reason}'
kubectl top pod <pod> -n <ns> --containers
kubectl get pod <pod> -n <ns> -o jsonpath='{.spec.containers[*].resources}'On the node, the kernel logs every OOM kill:
journalctl -k | grep -i -E 'oom|killed process'
For plain Docker:
docker inspect -f '{{.State.OOMKilled}} {{.State.ExitCode}}' <container>kubectl top shows samples, not peaks. To see spikes, graph container_memory_working_set_bytes against the limit in Prometheus or Grafana.
Fixes
- Stabilise: raise the memory limit to cover the observed peak plus headroom, and roll out.
- Size runtimes below the limit, for example
-XX:MaxRAMPercentage=75for Java. - Find the leak if usage grows without levelling off: take a heap profile and compare snapshots over time.
- Set the memory request equal to the limit for critical pods. That gives Guaranteed QoS when CPU is set the same way, and makes them the last to be evicted.
Common wrong fix
Raising the CPU limit. CPU limits throttle, they never cause OOM kills, so this changes nothing. The second trap is removing the memory limit. The pod stops being OOMKilled, but a leak now grows until the node runs out of memory, and the kubelet evicts pods (or the kernel kills processes) across workloads that did nothing wrong. Doubling the limit every time it fires only buys time. If the graph is a sawtooth that resets only on restart, it is a leak, and a bigger limit just spaces out the crashes.