Platforms 6 min read

Kubernetes Pod OOMKilled (Exit 137): Diagnose and Fix

OOMKilled with exit code 137 means a container went over its own memory limit. The fix depends on whether it leaked, spiked, or was simply given too little.

By BashPilot Team
BashPilot AI server management One request plans, executes and verifies the fix, on every server. See pricing

A Kubernetes pod that keeps restarting with OOMKilled and exit code 137 has been killed for using more memory than its limit allows. The container did not crash on its own, and the application log usually ends mid-sentence because SIGKILL gives it no chance to write anything. What you need to find out is why it needed that much memory.

Confirm that memory is the reason

Do not infer it from the restart count. Ask Kubernetes why the last container instance ended.

the reason and exit code of the last termination
kubectl get pod POD -n NAMESPACE -o jsonpath='{range .status.containerStatuses[*]}{.name}{"\t"}{.lastState.terminated.reason}{"\t"}{.lastState.terminated.exitCode}{"\t"}{.restartCount}{"\n"}{end}'
kubectl describe pod POD -n NAMESPACE | grep -A6 'Last State'

A line reading OOMKilled 137 confirms it. The reason is the proof, not the number: exit code 137 only says the process received SIGKILL, and a failed liveness probe or a manual kill produces the same code. The raw form of the same data is in kubectl get pod POD -o yaml, under lastState.terminated, where Kubernetes' own memory tutorial shows exitCode: 137 and reason: OOMKilled for a container that exceeded its limit. After several kills the pod's status column often changes to CrashLoopBackOff, which hides the real reason. Read the last state, not the status column. For the general restart-loop workflow, see Fixing CrashLoopBackOff Without Guessing.

See what the container actually asked for and used

configured requests, limits and QoS class, then live usage
kubectl get pod POD -n NAMESPACE -o jsonpath='{.spec.containers[*].resources}{"\n"}{.status.qosClass}{"\n"}'
kubectl top pod POD -n NAMESPACE --containers

kubectl top needs the metrics server installed in the cluster, and it shows current usage rather than history. If the numbers are empty, that is why. An empty resources result means no request or limit was set on that pod, so an out-of-memory kill would have come from the node itself running out of memory rather than from the pod's own limit.

Pattern you seeLikely causeWhat to do
Usage climbs steadily until the kill, then resets after the restartA memory leak, or a cache that never evictsFix the application. A higher limit only buys time
Usage jumps during one operation, such as a large upload or reportA peak that exceeds the limitRaise the limit above the real peak, or stream the work in chunks
Usage stays below the limit but the kill still happensA runtime sizing its heap from the node, not the containerSet the runtime's heap flag below the limit (see below)
Many pods on one node die togetherNode memory pressure and evictionCheck node capacity and total requests on that node

The third row is common with managed runtimes. A Java process can be told to size its heap as a percentage of the container's memory with -XX:MaxRAMPercentage, Node.js has --max-old-space-size, and Go 1.19 and later respect a soft limit through the GOMEMLIMIT variable. Leave headroom under the container limit for non-heap memory, because the limit counts everything the process uses.

Set requests and limits that fit

Pick numbers from observed usage, not from a guess. Take the typical working set for the request and a comfortable margin above the real peak for the limit. Memory cannot be reclaimed from a running process the way CPU time can be throttled, which is why many teams set the memory request equal to the limit on important workloads so that scheduling and enforcement agree.

memory settings in a container spec
resources:
  requests:
    memory: "256Mi"
  limits:
    memory: "512Mi"
or change a running deployment directly
kubectl set resources deployment/api -n NAMESPACE --requests=memory=256Mi --limits=memory=512Mi
kubectl rollout status deployment/api -n NAMESPACE

Note the units. Mi is a mebibyte, the binary unit Kubernetes uses in its own examples. Writing 512M instead of 512Mi is a different, slightly smaller number and a frequent source of off-by-a-few-percent surprises.

The same exit code appears on a plain Docker host when a container hits --memory. The diagnosis there uses docker inspect, and it is covered in Docker Container Exit Code 137. The kernel's role is identical, only the tooling differs.

Working through this for one pod is quick. Doing it for every restarting pod in a cluster, and remembering to check the node as well, is where it eats an afternoon. BashPilot can run these read-only checks as one request: last termination reasons, configured limits, current usage and node conditions. It proposes a resource change, applies it only after you approve, and checks the rollout afterwards.

In BashPilot

Finding why a pod keeps restarting

app.bashpilot.com
the api deployment in production keeps restarting, find out why
BashPilot

All 3 api pods show OOMKilled with exit code 137 on their last termination. Each has a 256Mi memory limit and is currently using about 240Mi. No node shows memory pressure, so this is the container limit, not eviction.

PodLast reasonRestartsLimitUsage now
api-7d9f-aOOMKilled (137)6256Mi241Mi
api-7d9f-bOOMKilled (137)5256Mi238Mi
api-7d9f-cOOMKilled (137)6256Mi244Mi
raise the limit to 512Mi and keep the request at 256Mi
BashPilot

That triggers a rolling restart of the deployment. Confirm to proceed, and I will watch the rollout and re-check usage afterwards. If usage keeps climbing past 400Mi, treat it as a leak.

bash
kubectl set resources deployment/api -n production --requests=memory=256Mi --limits=memory=512Mi
Example output, not a screenshot of a specific customer's server.

Try this on one of your own servers.

Start free trial

Prove it is fixed

  • kubectl rollout status completes and the pods stay Running with the restart count no longer rising.
  • kubectl top pod --containers shows usage settling well under the new limit during normal traffic and during the operation that used to trigger the kill.
  • kubectl get events -n NAMESPACE --sort-by=.lastTimestamp shows no new OOMKilling or Evicted entries after the change.

Catch it before the kill next time

A restart is the last alarm. Alert on memory approaching the limit instead. If you run Prometheus with kube-state-metrics, this expression gives you the ratio of working-set memory to the configured limit per container.

alert when a container uses more than 90% of its memory limit
max by (namespace, pod, container) (container_memory_working_set_bytes{container!=""})
/
max by (namespace, pod, container) (kube_pod_container_resource_limits{resource="memory"})
> 0.9

Review that alert after each release. A new feature that raises memory use will trip it long before the kernel does.

Share LinkedIn X
Questions

Frequently asked questions

What does exit code 137 mean in Kubernetes?

It is 128 plus 9, the SIGKILL signal. For a container that exceeded its memory limit, Kubernetes records `reason: OOMKilled` with `exitCode: 137` under the container's last terminated state. The kubelet restarts the container if the pod's restart policy allows it, which is why the restart count climbs.

How do I tell OOMKilled apart from a node eviction?

OOMKilled is recorded on the container's last state with exit code 137 and means it passed its own memory limit. An evicted pod shows the status `Evicted` with a message about node pressure, and `kubectl describe node` shows memory pressure in its conditions. The first is fixed in the pod's settings, the second on the node.

Should the memory request equal the limit?

Many teams set them equal for important workloads, because memory cannot be taken back from a running process the way CPU can be throttled. Equal values also give the pod the most predictable scheduling. It is a common practice, not a rule, so base the numbers on measured usage first.

Why does kubectl top show nothing?

`kubectl top` reads from the metrics server, which must be installed in the cluster. Without it the command returns an error or no data. Even when it works it shows current usage, not history, so use your monitoring system to see what happened before a kill.

Does raising the memory limit fix OOMKilled?

Only when the container was under-sized or has a predictable peak. If usage climbs steadily and never levels off, a higher limit just delays the next kill. Watch usage after the change, and if it keeps rising, fix the leak in the application.

Put your servers on autopilot.

Connect a server in about a minute. The first week is on us.