OOMKilled: when a container goes over its memory limit

Reproduced on k3s v1.31.5 (k3d) with kubectl v1.36.1.

What you see

$ kubectl get pod oom-demo -n lab
NAME       READY   STATUS             RESTARTS      AGE
oom-demo   0/1     CrashLoopBackOff   4 (65s ago)   2m35s

$ kubectl get pod oom-demo -n lab -o jsonpath='{.status.containerStatuses[*].lastState.terminated}'
{"containerID":"containerd://3064...","exitCode":137,"finishedAt":"2026-11-20T01:11:00Z","reason":"OOMKilled","startedAt":"2026-11-20T01:11:00Z"}

$ kubectl describe pod oom-demo -n lab
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
    Restart Count:  4
    Limits:
      memory:  32Mi

What it means

Each container's memory limit becomes a cgroup limit on the node. When the processes in that cgroup try to use more, the kernel OOM killer picks a process and kills it with SIGKILL. The container exits with code 137 and the kubelet records the reason OOMKilled.

There is a second path. If the node itself runs low on memory, the kernel can kill processes in any container, even ones under their limit. Containers without limits, or with requests far below real use, are the usual victims.

OOMKilled is different from Evicted. Eviction is the kubelet stopping a whole pod to protect the node. OOMKilled is the kernel killing a process inside a container.

Common causes

The limit is lower than normal use

The limit was set from a guess or copied from another service. Normal traffic needs more memory than that.

How to tell: Kills happen during steady load, not only at peaks. Memory graphs sit near the limit before each kill.

A memory leak

Memory grows slowly with every request until it reaches the limit. Restarting fixes it for a while.

How to tell: Memory rises steadily over hours, then drops to a baseline after each restart. Kills come at regular intervals.

Runtime heap set above the limit

JVM, Node.js or .NET heap settings allow the runtime to grow past the container limit. The runtime does not know it should collect garbage sooner.

How to tell: A fixed heap flag such as -Xmx or --max-old-space-size close to or above the container limit.

A large request or batch

One big upload, report or query loads too much into memory at once. Most of the time the app is fine.

How to tell: Kills line up with specific jobs or requests in the app logs, not with time.

Memory-backed volumes

An emptyDir with medium Memory is a tmpfs. Files written there count as memory for the pod.

How to tell: The pod spec has emptyDir medium: Memory and the app writes temp files to it.

The node ran out of memory

Pods on the node use far more than their requests, so the node is overcommitted. The kernel kills a process even though its own container was under its limit.

How to tell: The kill happened below the container limit. The node shows SystemOOM or MemoryPressure events around the same time.

A new release needs more memory

The new image or config uses more memory than the old one, and the limit was not changed with it. Startup can also need more than steady running.

How to tell: Kills started right after a deploy, or happen during startup. Compare the new image and config with the previous ReplicaSet.

How to diagnose it

  1. kubectl get pod <pod> -n <namespace> -o jsonpath='{.status.containerStatuses[*].lastState.terminated}'

    Confirm reason is OOMKilled and exitCode is 137. A 137 with reason Error is a different problem, see the exit code page.

  2. kubectl logs <pod> -n <namespace> -c <container> --previous > previous.log

    Save the killed container's logs, the pod YAML and its events before the next restart replaces them. Events are only kept for about an hour by default. The kill gives the process no chance to log, so the last lines show what it was doing just before.

  3. kubectl get pod <pod> -n <namespace> -o jsonpath='{.spec.containers[*].resources}'

    Note the memory request and limit for each container. No limit means the container can only be killed by node pressure.

  4. kubectl top pod <pod> -n <namespace> --containers

    Shows current memory per container, sidecars included. Needs metrics-server. It cannot show the peak that caused the kill, so use your monitoring history for the minutes before the restart.

  5. kubectl describe node <node>

    Check Allocated resources for memory requests and limits against capacity. Limits that add up to far more than capacity mean the node is overcommitted.

  6. kubectl get events -A --field-selector involvedObject.kind=Node,reason=SystemOOM

    SystemOOM events mean the kernel killed processes because the node was out of memory, not just one container.

How to fix it

Raise the memory limit

Set the limit above the real peak you see in metrics, with some headroom. Raise the request too so the scheduler places the pod on a node that has the memory.

resources:
  requests:
    memory: 512Mi
  limits:
    memory: 512Mi

Trade-off: Fewer pods fit per node, which can mean more nodes and more cost. It also hides a leak for longer.

Size the runtime to the container

Let the runtime read the container limit instead of a fixed heap size. For the JVM use -XX:MaxRAMPercentage. For Node.js set --max-old-space-size below the limit. For Go set GOMEMLIMIT a little below the limit.

Trade-off: Leave room for memory outside the heap, such as threads, buffers and native libraries. A heap that fills the limit still gets killed.

Fix the leak or the large batch

Use a heap profile or memory dump to find what grows. Stream large inputs instead of loading them whole.

Trade-off: Takes engineering time. Raise the limit as a stopgap while you work on it.

Set requests equal to limits

This gives the pod the Guaranteed QoS class. The scheduler reserves its full memory, so it is less likely to be hit by node memory pressure.

Trade-off: Reserved memory sits idle when the pod is quiet. You pay for the peak all the time.

How to stop it coming back

  • Alert when a container's working set stays close to its limit, before the kill happens.
  • Set memory requests close to real use so nodes are not overcommitted.
  • Load test new releases with realistic data sizes, not only request counts.
  • Run the Vertical Pod Autoscaler in recommendation mode to see suggested values without applying them.
  • Graph memory per container against its limit and put deploys on the same timeline, so you can see the shape of the climb.

How KubeGraf investigates it

Agents propose competing explanations and cite the evidence behind each one. How KubeGraf handles Kubernetes incidents.

Frequently asked questions

What does OOMKilled mean in Kubernetes?

The container's memory limit becomes a cgroup limit on the node. When the processes in it try to use more, the kernel kills one with SIGKILL. The kubelet records the reason OOMKilled.

How do I set the container memory limit?

Set resources.limits.memory on the container, above the real peak you see in metrics with some headroom. Raise resources.requests.memory too, so the scheduler puts the pod on a node that has the memory.

Why does OOMKilled show exit code 137?

137 is 128 plus 9, the signal number of SIGKILL. The exit code only says the process got SIGKILL. It means out of memory only when the reason field says OOMKilled.

How do I tell if a memory leak causes it?

A leak shows as memory that climbs steadily over hours and drops back after each restart. The kills then come at regular intervals. A heap profile or memory dump shows what grows.

Last updated . Try KubeGraf Freemium.

Related

Kubernetes documentation