Skip to content

OOMKilled (exit code 137): container exceeds its memory limit

Kubernetestested on RKE2 v1.37.2

OOMKilled with exit code 137 means: the kernel killed inside the container's memory limit. The process had no chance to write an error message – Last State and the node's kernel log show the reason.

Symptom

kubectl -n tag05 get pods -l app=speicher -o wide | cut -c1-88
NAME                        READY   STATUS      RESTARTS      AGE   IP           NODE
speicher-7489b76474-qncx6   0/1     OOMKilled   1 (17s ago)   20s   10.42.2.16   worker2

Here a process loads 100 MB into memory; the limit is 64Mi. The NODE column tells you where to read the kernel log next.

Diagnosis

Put the reason and exit code of the last run next to the limit.

kubectl -n tag05 describe pod -l app=speicher \
  | sed -n '/Last State/,/Exit Code/p;/Limits/,/memory/p'
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
    Limits:
      memory:  64Mi

Causes

Limits 64MiLimit lower than what the app needs

The application needs more memory than the limit allows. In the example, tail buffers everything up to the first line ending – with /dev/zero that means 100 MB.

Killed processThe kernel kills the whole container

The node's kernel log has the proof. Under cgroup v2 the kubelet sets memory.oom.group; the kernel then kills every process in the container, not just the largest one.

sudo journalctl -k --since -5min | grep 'Killed process' | cut -c1-88
Nov 20 07:27:20 worker2 kernel: Memory cgroup out of memory: Killed process 29137 (sh) t
Nov 20 07:27:20 worker2 kernel: Memory cgroup out of memory: Killed process 29157 (head)
Nov 20 07:27:20 worker2 kernel: Memory cgroup out of memory: Killed process 29158 (tail)

137 without OOMKilledNot OOM but a SIGKILL from outside

Without Reason OOMKilled and a kernel log entry, it was a SIGKILL from outside – for example from a liveness probe, once the grace period expired.

Fix

Set the limit to what the app needs plus headroom and roll out again.
kubectl -n tag05 set resources deploy/speicher \
  --requests=memory=160Mi --limits=memory=160Mi
kubectl -n tag05 rollout status deploy/speicher
kubectl -n tag05 get pods -l app=speicher
kubectl -n tag05 logs deploy/speicher
NAME                        READY   STATUS    RESTARTS   AGE
speicher-67f57fff74-l4z8r   1/1     Running   0          42s
lade Cache

Don't: Guessing the limit. Derive it from measurements (kubectl top, metrics over days); the JVM and friends need heap plus overhead.

▶
Break it yourself and find it – free
Debugging Kubernetes, day 5: six crashes from a typo to readOnlyRootFilesystem, with a drill to reproduce each one.
Go to day 5 →

FAQ

How do I see at a glance which Pods were last OOMKilled?

kubectl get pods -o custom-columns=NAME:.metadata.name,LAST:.status.containerStatuses[0].lastState.terminated.reason shows the reason of the last terminated run.

How do I notice OOM kills before anyone goes looking?

With alerts on kube_pod_container_status_last_terminated_reason{reason="OOMKilled"} and on rising restart counters.

Related error patterns

More