OOMKilled with exit code 137 means the Linux kernel's OOM killer sent SIGKILL (128 + 9 = 137) to your container's process because the container's memory cgroup hit its limit. In Kubernetes that limit is resources.limits.memory; in Docker it is --memory. The fix is to find the real memory peak, then either raise the limit to fit it or make the runtime (JVM, Node.js, Python, Go) stay under it.
That sounds simple, and the first part often is. The trouble is that three different events look alike from a distance: a container OOM kill, a node-level OOM kill, and a kubelet eviction under node memory pressure. They have different causes and different fixes, so the first job is to work out which one you have.
What OOMKilled and Exit Code 137 Mean
Exit code 137 only tells you the process got SIGKILL. Kubernetes adds the reason. Check both:
kubectl get pod api-6f7b9c-zq2lp -n shop \
-o jsonpath='{range .status.containerStatuses[*]}{.name}{"\t"}{.lastState.terminated.reason}{"\t"}{.lastState.terminated.exitCode}{"\n"}{end}'
# api OOMKilled 137
Or in kubectl describe pod:
Last State: Terminated
Reason: OOMKilled
Exit Code: 137
Restart Count: 6
If the reason is OOMKilled, the kernel killed the process for memory. If the exit code is 137 but the reason is Error, something else sent SIGKILL. The usual culprit is a failing liveness probe or a slow shutdown: the kubelet sends SIGTERM, waits terminationGracePeriodSeconds, then sends SIGKILL. That is a probe or shutdown problem, not a memory problem.
For plain Docker:
docker inspect --format '{{.State.OOMKilled}} {{.State.ExitCode}}' api
# true 137
When it keeps happening, the pod ends up in a restart loop. The restart mechanics are the same as any crash, which our CrashLoopBackOff guide covers; this post is about the memory side. If the pod never gets as far as starting because the image cannot be fetched, that is a different failure, covered in our ImagePullBackOff guide.
Container Limit OOM vs Node Memory Pressure Eviction
These are the three cases, and how to tell them apart:
| What you see | What happened | Who acted |
|---|---|---|
Reason: OOMKilled, container restarts, pod stays on the node |
Container exceeded its own memory limit | Kernel OOM killer, inside the container's cgroup |
Reason: OOMKilled on a container that was under its limit |
The whole node ran out of memory before the kubelet could react | Kernel OOM killer, node-wide |
Pod Status: Failed, Reason: Evicted, message mentions low memory |
Node crossed the kubelet's memory.available eviction threshold |
Kubelet |
Container limit OOM
This is the common case. The container's cgroup has memory.max set from your limit. The resource management docs are precise about it: memory limits are enforced by the kernel with OOM kills, and only "when the kernel detects memory pressure", which means enforcement is reactive. Usage that briefly goes over can survive; usage that can't be reclaimed gets killed.
Node-level OOM
If the node itself runs out of memory before the kubelet evicts anything, the kernel picks a victim across the whole node. The kubelet biases that choice with oom_score_adj, per the node-pressure eviction docs:
| QoS class | oom_score_adj |
|---|---|
| Guaranteed | -997 |
| BestEffort | 1000 |
| Burstable | min(max(2, 1000 − (1000 × memoryRequestBytes) / machineMemoryCapacityBytes), 999) |
In plain terms, a Burstable container using far more memory than it requested is first in line. So a container can be OOMKilled while under its own limit, purely because its request was too low and a neighbour pushed the node over. Overcommitted nodes (sum of limits far above capacity) make this likely.
Kubelet eviction
The kubelet watches memory.available and evicts pods when it crosses a threshold. The default hard threshold on Linux is memory.available<100Mi. Eviction order is based on whether usage exceeds requests, then priority, then how far over the request the pod is. Evicted pods are not restarted in place; their controller creates replacements, possibly on another node. If you see Evicted, you have a node capacity and requests problem, not a limit problem.
How cgroup v2 Accounts for Container Memory
Almost every current distro runs cgroup v2, and Kubernetes has deprecated cgroup v1 since 1.35: the kubelet no longer starts on a cgroup v1 node by default unless you set failCgroupV1: false. So it's worth knowing the v2 files, because they tell you more than any dashboard.
Inside the container (or under the pod's cgroup on the node):
cat /sys/fs/cgroup/memory.max # the limit, in bytes ("max" = none)
cat /sys/fs/cgroup/memory.current # usage right now
cat /sys/fs/cgroup/memory.peak # highest usage recorded
cat /sys/fs/cgroup/memory.events # counters, including oom_kill
grep -E '^(anon|file|kernel|shmem|sock) ' /sys/fs/cgroup/memory.stat
What to look for:
memory.peakis the highest usage recorded for the cgroup since it was created, according to the kernel cgroup v2 documentation. This is the number you size limits from, not an average.memory.eventshasoom_kill, the number of processes in this cgroup killed by any OOM killer, andoom_group_kill. Ifoom_killis climbing while the container keeps running, a child process (a worker, a sidecar shell, a build step) is being killed, not the main process.memory.statsplitsanon(heap, stacks, anything not backed by a file) fromfile(page cache). Page cache is charged to the container but can be reclaimed, so a highfilenumber alone rarely causes an OOM kill. Growinganondoes.shmemincludes tmpfs. Amedium: MemoryemptyDir counts against the container's memory, so a job writing scratch files to RAM-backed storage can OOM with a small heap.
Whole-container OOM kills
On cgroup v2, the kubelet sets memory.oom.group on container cgroups by default, which tells the kernel to kill all processes in the cgroup together. The kubelet configuration reference documents the singleProcessOOMKill setting: when true, it stops the flag being set and processes are killed one at a time, the old cgroup v1 behaviour; on cgroup v2 Linux the default is false.
This matters for multi-process containers. With gunicorn, uWSGI, PHP-FPM or nginx workers, an OOM used to kill one worker, the master would fork a new one, and you might never notice. With group kill, the whole container dies and restarts. Teams sometimes read that as "OOMKilled started after the upgrade" when the memory use was always there.
Finding the Real Memory Peak
kubectl top shows a recent sample from metrics-server. It is fine for "roughly how big is this" and useless for spikes that last a second. Use something that records the maximum.
Prometheus with cAdvisor metrics. The kubelet's eviction logic uses the working set (usage minus inactive file cache), and so should you:
max_over_time(
container_memory_working_set_bytes{namespace="shop", container="api"}[7d]
)
Compare it with the limit:
max by (pod) (container_memory_working_set_bytes{namespace="shop", container="api"})
/
max by (pod) (kube_pod_container_resource_limits{namespace="shop", container="api", resource="memory"})
Anything that regularly crosses 0.9 is a candidate for the next OOM kill. Scrape intervals still smooth very short spikes, so for a definitive number read memory.peak directly.
memory.peak from a running container. Run a representative load (a batch job, a load test, a full day of traffic) and read it:
kubectl exec -n shop api-6f7b9c-zq2lp -- cat /sys/fs/cgroup/memory.peak
The kernel log on the node. When the kernel kills a process it logs which one and how much anonymous memory it held, which tells you whether it was the main process or a helper:
journalctl -k --since "1 hour ago" | grep -iE "out of memory|oom-kill|killed process"
Runtime Heap Sizing in Containers
Most OOM kills I've debugged were not leaks. They were a runtime sized for a different amount of memory than the container actually had, or a heap set to the full limit with no room left for everything else.
Java and the JVM
Modern JVMs read the cgroup limit (container support has been on by default since JDK 10, backported to 8u191; see JDK-8146115). The catch is the default heap size. The java command reference says -XX:MaxRAMPercentage defaults to 25 percent. In a 2 GiB container, that is a 512 MiB heap: too small, so teams set -Xmx2g, which is too big, because the JVM also needs metaspace, thread stacks, code cache, GC structures and direct buffers outside the heap.
A sensible starting point:
env:
- name: JAVA_TOOL_OPTIONS
value: "-XX:MaxRAMPercentage=70 -XX:+ExitOnOutOfMemoryError"
resources:
requests:
memory: "2Gi"
limits:
memory: "2Gi"
Then measure. If memory.peak sits near the limit while the heap is half empty, the extra memory is off-heap: enable -XX:NativeMemoryTracking=summary and run jcmd <pid> VM.native_memory summary to see which area is growing. Netty direct buffers and lots of threads are the usual suspects. -XX:+ExitOnOutOfMemoryError makes a Java heap OOM exit fast and visibly instead of limping along in GC thrash.
Node.js
V8 has its own old-space limit, and it is separate from the container limit. When the V8 heap fills, Node dies with FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory and a non-137 exit code, which is not an OOM kill at all. When the container limit is lower than what V8 thinks it can use, you get OOMKilled instead.
Set the heap explicitly. The Node.js CLI docs describe --max-old-space-size (in MiB) and, in current releases, --max-old-space-size-percentage, which sizes the old space as a percentage of available memory and takes precedence over the fixed size:
env:
- name: NODE_OPTIONS
value: "--max-old-space-size=1536" # for a 2Gi limit
Leave room for buffers, native addons and the young generation; around 75 percent of the limit is a reasonable first guess for a single-process service. If you run cluster mode or worker threads, each one has its own heap, so divide accordingly.
Python
CPython has no heap cap to tune, so control comes from process count and allocation patterns:
- Workers multiply memory. Four gunicorn workers each holding a 400 MiB model is 1.6 GiB before any requests. Size the limit from
workers × per-worker peak + master, or load the model before forking (--preload) so pages are shared copy-on-write. - Recycle leaky workers.
--max-requests 1000 --max-requests-jitter 100restarts workers periodically, which hides slow leaks until you can fix them. - glibc arenas. Heavily threaded Python on glibc can fragment across many malloc arenas. Setting
MALLOC_ARENA_MAX=2often flattens memory growth; measure before and after. - pandas and NumPy allocate outside Python's own allocator.
tracemallocwon't show everything;memory.peakwill.
Go
Go 1.19 added a soft memory limit, set with the GOMEMLIMIT environment variable or runtime/debug.SetMemoryLimit. Set it to roughly 90 percent of the container limit so the GC works harder before the kernel steps in.
Requests and Limits Strategy for Memory
Memory is not compressible. CPU over its limit is throttled; memory over its limit is killed. That changes how you set it:
- Set memory request equal to memory limit for anything important. It makes eviction and node-OOM ordering predictable and stops the scheduler packing nodes on optimistic requests. If CPU request also equals CPU limit, the pod is Guaranteed and gets
oom_score_adj-997. - Size the limit from the measured peak, plus headroom. Take the 7-day
max_over_timeof working set (ormemory.peakunder a realistic load) and add 15 to 25 percent. Revisit after major releases. - Don't run without a memory limit in shared clusters. A BestEffort or limitless Burstable pod is the first victim on node OOM and can take neighbours with it on the way.
- Watch the node, too. Check
kubectl describe nodeforAllocated resources. If memory limits total far above allocatable, a busy hour will produce node OOMs that no single container setting fixes. - Set
systemReservedandkubeReservedon self-managed nodes so the kubelet and runtime aren't competing with pods for the last few hundred megabytes.
Fixing It Without Restarts: VPA and In-Place Resize
Since Kubernetes 1.35 in-place pod resize is stable, so you can raise a running container's memory without recreating the pod:
kubectl patch pod api-6f7b9c-zq2lp -n shop --subresource resize --patch \
'{"spec":{"containers":[{"name":"api","resources":{"requests":{"memory":"3Gi"},"limits":{"memory":"3Gi"}}}]}}'
Two caveats. First, a bigger cgroup limit doesn't help a JVM whose -Xmx was fixed at startup, so for those containers set resizePolicy for memory to RestartContainer. Second, decreasing memory is best-effort: the kubelet tries to avoid OOM kills but makes no guarantee. We walk through the details in our in-place pod resize guide.
Patching pods by hand doesn't survive the next rollout. For ongoing sizing, the Vertical Pod Autoscaler's InPlaceOrRecreate update mode applies its recommendations in place and falls back to eviction if it can't; the VPA feature docs list it as GA from VPA 1.6.0, and one of its triggers is a quick OOM. A pragmatic setup is VPA in Off mode for a week to collect recommendations, then copy those numbers into your manifests or let VPA manage them for stateless services.
If you're planning a cluster upgrade at the same time, check the node and resource changes in our Kubernetes 1.38 upgrade checklist before you roll nodes.
OOMKilled in Docker and Docker Compose
Everything above applies to Docker, minus the scheduler:
docker run -d --name api --memory 1g --memory-swap 1g myorg/api:2.3.1
docker stats --no-stream api
docker inspect --format '{{.State.OOMKilled}} {{.HostConfig.Memory}}' api
Setting --memory-swap equal to --memory disables swap for the container so behaviour matches a typical Kubernetes node. In Compose, set the limit under deploy.resources.limits.memory (or mem_limit). On Docker Desktop, the whole Linux VM has its own memory cap, so a container can be killed by the VM running out long before it hits its own limit; raise the VM's memory in settings.
Frequently Asked Questions
Is exit code 137 always an out-of-memory kill?
No. 137 means the process received SIGKILL. In Kubernetes, check lastState.terminated.reason: OOMKilled confirms memory, while Error with 137 usually means the kubelet killed the container after a failed liveness probe or an expired termination grace period. In Docker, check .State.OOMKilled.
Why was my container OOMKilled when it was below its memory limit?
The node ran out of memory and the kernel chose your container. Burstable pods using much more than their memory request get high oom_score_adj values and are killed first. Raise the memory request to match real usage, and stop overcommitting memory limits on that node pool.
Does page cache count toward the Kubernetes memory limit?
It is charged to the container's cgroup, but the kernel can reclaim it under pressure, so it rarely causes an OOM kill by itself. The kubelet's working-set metric subtracts inactive file cache for that reason. Anonymous memory (heap, stacks) and tmpfs are what usually push a container over.
What is the difference between OOMKilled and Evicted?
OOMKilled is the kernel killing a process when a memory cgroup is full; the container restarts in the same pod. Evicted is the kubelet removing a whole pod because the node crossed an eviction threshold such as memory.available<100Mi; the controller creates a new pod, possibly elsewhere.
How much memory should I give a JVM container?
Start with -XX:MaxRAMPercentage around 70 to 75 so the heap gets most of the limit and the rest covers metaspace, threads, code cache and direct buffers. Then compare memory.peak with heap usage under real load and adjust. Avoid setting -Xmx equal to the container limit.
Bottom Line
Treat OOMKilled as a measurement problem first. Confirm the reason (not just 137), decide whether it was the container limit, the node, or an eviction, and read memory.peak and memory.events to get the real peak. Then size the runtime to the container (JVM percentage, Node heap flag, Python worker count, GOMEMLIMIT), set memory requests equal to limits for anything important, and use VPA or in-place resize to keep the numbers honest as the service changes.