Back to articles

OOMKilled (exit code 137): leak or limit?

Exit code 137 means SIGKILL, and "OOM" covers three different mechanisms: a container hitting its own limit, the node running out of memory, and a kubelet eviction. How to tell them apart from the evidence, how to read a memory graph as leak or undersized limit, and why JVM, Go and Node.js defaults cause kills in applications that aren't leaking.

A container is killed for memory, someone doubles the limit, and the alert stops. Three weeks later it's back, at twice the size. Raising the limit answered a question nobody asked: whether the container needed more memory, or was going to use whatever it was given.

OOMKilled is also used loosely for three different mechanisms, and exit code 137 covers a fourth thing that has nothing to do with memory. This article is about telling them apart, and then deciding between "the limit is wrong" and "the application is wrong" with data.

Who this is for: engineers with a container that keeps restarting with exit code 137, or writing the post-incident review for one.

What you walk away with: the evidence that separates the three mechanisms, a method for reading a memory graph as leak or undersized limit, and the runtime settings that cause kills in applications that aren't leaking.

Everything here is drawn from documentation and source: Kubernetes v1.37, containerd v2.4, Linux v6.12, JDK 25, Go 1.25, Node.js 24 and 26. On 17 November 2026 the limit kills, the commands, the JVM and Node.js defaults and the resize were run on one cluster (GKE 1.36.4); node-level OOM, eviction and the PromQL queries were not. The mechanism behind the kills is in Memory pressure: who dies first.

Step 1: confirm it's an OOM kill

kubectl get pod <pod> -n <namespace> -o jsonpath='{range .status.containerStatuses[*]}{.name}{"\t"}{.restartCount}{"\t"}{.lastState.terminated.reason}{"\t"}{.lastState.terminated.exitCode}{"\t"}{.lastState.terminated.finishedAt}{"\n"}{end}'

Illustrative output:

api     4       OOMKilled       137     2026-10-09T09:42:17Z
proxy   0

Error with 137 is a SIGKILL the runtime didn't tie to an OOM kill. The usual senders:

Sender Evidence
The kubelet, after a failed liveness probe and an expired grace period Unhealthy and Killing events.
The kubelet, when a pod is deleted and the container ignores SIGTERM The pod was terminating.
An OOM kill the runtime failed to record containerd's source describes a race where the cgroup is gone before the counter is read. Check the kernel log (step 2).
Something inside the container A script calling kill -9.

Don't size memory on the strength of a bare 137. CrashLoopBackOff forensics has the full exit-code table.

Step 2: which of the three mechanisms?

Container-limit OOM Node-level OOM Kubelet eviction
Trigger The container reaches its own limit; the kernel kills inside its cgroup The node runs out; the kernel picks a process anywhere on it The node crosses an eviction threshold; the kubelet terminates a pod
Afterwards Container restarted in place; restart count goes up The same, for the container that held the victim Pod phase Failed, reason Evicted. A controller creates a new pod.

Evidence for a container-limit OOM

Reason OOMKilled, and usage at the limit just before the kill. The kernel log on the node tells a limit kill from a node-level one:

journalctl -k --since "1 hour ago" | grep -i -E "oom-kill:|killed process"

In the Linux v6.12 source, a limit kill is logged as Memory cgroup out of memory: Killed process <pid> (<name>) …, after an oom-kill: line carrying oom_memcg=<cgroup path>. A node-level kill reads Out of memory: Killed process …, with global_oom in the oom-kill: line.

Evidence for a node-level OOM

The kubelet records an event on the Node when it reads a system-level OOM kill from the kernel log:

kubectl get events -A --field-selector reason=SystemOOM

Illustrative output:

Warning  SystemOOM  node/worker-3  System OOM encountered, victim process: java, pid: 48211

The second sign is a container killed well below its own limit, or with no limit at all. Its status doesn't separate this from a limit kill: containerd reads the same counter, so expect OOMKilled here too.

The killed container's limit isn't the thing to fix. The kernel kills the process with the highest score, not necessarily the one that grew (Who dies first has the calculation). Look for the container on that node that used far more than it requested.

Evidence for a kubelet eviction

kubectl get pod <evicted-pod> -n <namespace> -o jsonpath='{.status.reason}{": "}{.status.message}{"\n"}'

Illustrative output:

Evicted: The node was low on resource: memory. …

Eviction is a capacity and requests problem.

Step 3: what counts towards the limit

From the kernel's cgroup v2 documentation (v6.12), with the field in the cgroup's memory.stat:

Counts towards the limit Field Notes
Anonymous memory: heap, stacks anon
Page cache for files the container reads and writes file Mostly reclaimable. The OOM killer runs only when usage reaches the limit and can't be reduced.
tmpfs, including emptyDir with medium: Memory shmem, also counted in file Charged to the container that wrote the files, and not reclaimable under pressure.
Kernel memory used on the container's behalf kernel, sock Kernel stacks, page tables, slab, network buffers.

Usage near the limit isn't always a problem. container_memory_usage_bytes is everything in the cgroup. container_memory_working_set_bytes is usage minus inactive_file, and it's what the kubelet uses for eviction. Size and alert on the working set, but it still counts active file cache, so a container doing heavy file I/O can sit near its limit without being killed. The kernel acts on total usage when reclaim fails, so the last working-set sample before a kill can also be below the limit.

A flat heap doesn't rule out an OOM. Look at tmpfs first:

kubectl get pod <pod> -n <namespace> -o jsonpath='{range .spec.volumes[?(@.emptyDir.medium=="Memory")]}{.name}{"\t"}{.emptyDir.sizeLimit}{"\n"}{end}'

Without a sizeLimit, a memory-backed volume was sized to the pod's memory limit in the test, so the only bound is that limit. A restart doesn't empty it: the killed container then failed to start (container init was OOM-killed).

For the breakdown on a cgroup v2 node:

kubectl exec <pod> -n <namespace> -c <container> -- cat /sys/fs/cgroup/memory.stat
kubectl exec <pod> -n <namespace> -c <container> -- cat /sys/fs/cgroup/memory.events

memory.events has the fields low, high, max, oom, oom_kill and oom_group_kill. Inside a container on the test cluster, /sys/fs/cgroup was its own cgroup: memory.max showed the limit.

Step 4: leak or undersized limit?

You need the working set over time, across several restarts:

container_memory_working_set_bytes{namespace="shop", pod=~"api-.*", container="api"}

Plot it over a few days, next to whatever drives the workload. The table is a heuristic: the readings are judgement, not documentation, and none was reproduced for this article.

Shape Likely reading Response
Rises steadily regardless of load, drops at each restart, rises again at a similar slope Leak, or a cache without a bound Fix the application. A higher limit only lengthens the interval between kills.
Levels off soon after start, close to the limit. Kills coincide with load peaks. Undersized limit Raise the limit to the measured peak plus headroom.
Killed seconds after start, every time Limit below what start-up needs, or a runtime setting is wrong Step 6, then the limit.
Flat for days, then a sudden jump to the limit A specific request or job allocates a lot at once Find the trigger in the application logs. Bound it or size for it.

To separate the first two rows, look at a quiet period: a leak keeps climbing while idle. To find what grows, compare two heap captures: a JVM heap dump (jcmd <pid> GC.heap_dump <file>), a Go heap profile (runtime/pprof) or a Node.js heap snapshot (v8.writeHeapSnapshot()).

To count kills, the kubelet's cAdvisor endpoint exposes container_oom_events_total: in v1.37, the OOM kills the kubelet reads from the kernel log, per cgroup. kube-state-metrics exposes the last termination reason, with the same namespace, pod and container labels:

kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} == 1

The counter catches the case from step 1 that the status misses. On cgroup v2 the kubelet's default is a group kill: every process in the container dies, which gives the restart you see. On cgroup v1 nodes, or with singleProcessOOMKill: true, the kernel can kill one worker while the main process survives. A rising counter without restarts points there. Test it first: on the v1.36 cluster it stayed 0 through twenty kills.

Step 5: multi-container pods and sidecars

kubectl get pod <pod> -n <namespace> -o jsonpath='{range .spec.containers[*]}{.name}{"\t"}{.resources.limits.memory}{"\n"}{end}'

A LimitRange may also have supplied a limit nobody chose.

Step 6: runtimes that don't fit the limit

The runtime may have sized itself without regard to the limit, or been told to use all of it.

JVM

The JVM derives its default maximum heap from the container's memory limit, and the default isn't one number. With the JDK 25 defaults (MaxRAMPercentage 25, MinRAMPercentage 50), the heap is 50% of a limit below roughly 250MiB, about 125MB flat from there to roughly 500MiB (49% of a 256Mi limit), and 25% above that.

Set -XX:MaxRAMPercentage and check what the JVM computed:

kubectl exec <pod> -n <namespace> -c <container> -- java -XX:+PrintFlagsFinal -version | grep -E "MaxHeapSize|MaxRAMPercentage"

This starts a second JVM in a container that may be near its limit, and it doesn't see the application's command-line flags. Where the image has jcmd, jcmd <pid> VM.flags reads the running process.

The opposite mistake is setting -Xmx equal to the container limit. Metaspace, thread stacks, the code cache and direct buffers sit outside the heap, so the kernel kills the process before the JVM has a reason to throw OutOfMemoryError.

As a rule of thumb, an OutOfMemoryError for heap space in the logs means the heap was too small or leaked. OOMKilled without one means the process as a whole outgrew the container; Native Memory Tracking (-XX:NativeMemoryTracking=summary, read with jcmd <pid> VM.native_memory summary) shows the non-heap side.

Go

The Go runtime doesn't read the container limit: by default its memory limit is off. The GOMEMLIMIT environment variable gives it a soft limit to work towards. The value is in bytes with an optional suffix: B, KiB, MiB, GiB or TiB, so 900MiB and not 900Mi. It works alongside GOGC and applies even with GOGC=off. It is soft: the GC guide says the runtime lets memory use pass the limit sooner than spend all its time collecting, so a program whose live heap needs more can still be OOM-killed. It also doesn't cover memory allocated by C code. The guide's rule of thumb is 5 to 10% of headroom below the container's limit.

Node.js

V8's old-generation heap has its own maximum, set with --max-old-space-size in MiB. Without the flag, Node.js 24 and 26 hand V8 the container's limit to derive a default from. The resulting figure isn't documented, so read v8.getHeapStatistics().heap_size_limit in the application. It measured about 260MiB under a 256Mi and under a 512Mi limit.

If the maximum is too close to the container's limit, the kernel kills the process first. If it's far below, the process prints FATAL ERROR: … JavaScript heap out of memory and aborts with memory to spare. That is an abort, not an OOM kill: exit code 134 (SIGABRT), or 139 when Node.js is PID 1.

Mitigation while you investigate

Don't raise the limit before you know which case it is. If the service is down and the evidence points to an undersized limit, in-place resize raises the limit on the running pod. It is stable since Kubernetes v1.35 and needs kubectl v1.32 or later:

kubectl patch pod <pod> -n <namespace> --subresource resize --patch \
  '{"spec":{"containers":[{"name":"api","resources":{"requests":{"memory":"1Gi"},"limits":{"memory":"1Gi"}}}]}}'

Its limits, from the resize documentation:

The Vertical Pod Autoscaler can adjust requests and limits from observed usage, but it follows a leak upwards as readily as real demand, so it doesn't replace the diagnosis.