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.
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.
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
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 see | Likely cause | What to do |
|---|---|---|
| Usage climbs steadily until the kill, then resets after the restart | A memory leak, or a cache that never evicts | Fix the application. A higher limit only buys time |
| Usage jumps during one operation, such as a large upload or report | A peak that exceeds the limit | Raise the limit above the real peak, or stream the work in chunks |
| Usage stays below the limit but the kill still happens | A runtime sizing its heap from the node, not the container | Set the runtime's heap flag below the limit (see below) |
| Many pods on one node die together | Node memory pressure and eviction | Check 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.
resources:
requests:
memory: "256Mi"
limits:
memory: "512Mi"
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.
Finding why a pod keeps restarting
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.
| Pod | Last reason | Restarts | Limit | Usage now |
|---|---|---|---|---|
| api-7d9f-a | OOMKilled (137) | 6 | 256Mi | 241Mi |
| api-7d9f-b | OOMKilled (137) | 5 | 256Mi | 238Mi |
| api-7d9f-c | OOMKilled (137) | 6 | 256Mi | 244Mi |
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.
kubectl set resources deployment/api -n production --requests=memory=256Mi --limits=memory=512Mi
Try this on one of your own servers.
Start free trialProve it is fixed
kubectl rollout statuscompletes and the pods stayRunningwith the restart count no longer rising.kubectl top pod --containersshows 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=.lastTimestampshows no newOOMKillingorEvictedentries 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.
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.