Kubernetes Exit Code 137: Fixing OOMKilled Node Pods
Why Kubernetes terminates Node.js pods with exit code 137, how cgroup limits clash with V8 heap sizing, and how to configure memory requests and headroom.
Most engineering teams discover Kubernetes exit code 137 during the quietest hours of the week. Prometheus memory graphs often display a gentle upward incline rather than a dramatic spike, and application error logs show zero uncaught exceptions before the pod vanishes. A few seconds later, kubectl get pods displays CrashLoopBackOff or OOMKilled with exit code 137. In containerized environments, this abrupt death happens because the Linux kernel out-of-memory killer terminates processes with an uncatchable SIGKILL the moment container memory breaches its cgroup ceiling. When running Node.js workloads, setting --max-old-space-size to match your container memory limit creates a guaranteed crash vector, because V8 heap bounds do not constrain native buffers or runtime overhead. Sizing your V8 heap to 70% of the container memory limit and auditing external buffers stops sudden kernel evictions permanently.
Quick OOMKilled Triage Checklist
- Verify Termination Reason: Inspect the pod status with
kubectl get pod <pod-name> -o yamland checkstatus.containerStatuses[].lastState.terminated.reasonto confirmOOMKilledandexitCode: 137. - Rebalance Heap Headroom: Reduce
--max-old-space-sizeso that it occupies no more than 70% of the container’sresources.limits.memory. For a 1Gi container, set--max-old-space-size=768. - Audit Native Buffers & Stream Leaks: Check whether endpoints buffering large file uploads, uncompressed API responses, or crypto operations are allocating memory outside the V8 heap. Similar memory and concurrency leaks are examined in our guide on diagnosing Node.js event loop lag and bottlenecks.
- Order an Infrastructure Assessment: When microservice containers repeatedly crash under variable traffic, teams schedule our 48-Hour Codebase Audit to identify memory leaks, tune container QoS classes, and eliminate cloud infrastructure cost overages.
The Anatomy of Exit Code 137: How the Kernel Kills Containers
Exit code 137 is not an application-level error generated by Node.js or the container runtime. It is a mathematical convention of Unix process management indicating that the operating system kernel terminated a process with signal 9 (SIGKILL).
+-----------------------------------------------------------------------------------+
| Linux Kernel OOM Termination Flow |
+-----------------------------------------------------------------------------------+
| 1. Container Memory Usage Escalates |
| Node.js V8 Heap (650MB) + Native Buffers (320MB) + Libuv Overhead (60MB) |
| Total RSS = 1,030 MB |
| |
| 2. Cgroup Ceiling Reached |
| Kubernetes container limit = 1,024 MB (1Gi) |
| cgroup controller detects memory.current > memory.max |
| |
| 3. Kernel OOM Killer Intervenes |
| Kernel selects container process based on oom_score_adj |
| Sends SIGKILL (Signal 9) -> Process cannot intercept or catch |
| |
| 4. Kubernetes Records Pod State |
| Exit Code = 128 + Signal 9 = 137 |
| Container Status -> Reason: OOMKilled |
+-----------------------------------------------------------------------------------+
When you define container memory limits in a Kubernetes manifest, the kubelet translates those limits into Linux Control Groups (cgroups). In cgroups v1, this is represented by memory.limit_in_bytes; in cgroups v2, it maps to memory.max.
The cgroup controller tracks every page of physical memory allocated by the container, including:
- Anonymous Memory: Process stack, heap, and dynamic memory allocations.
- Page Cache: Cached disk blocks and filesystem buffers.
- Kernel Memory: Socket buffers, page tables, and network driver queues.
If the aggregate memory footprint exceeds the cgroup ceiling, the kernel cannot fulfill new memory allocations. Unlike virtual machines with swap partitions, Kubernetes nodes typically run with swap disabled. The kernel invokes its Out-Of-Memory Killer, selects the rogue process according to its oom_score_adj rating, and delivers an immediate SIGKILL.
Because SIGKILL cannot be handled, caught, or ignored by application runtimes, the Node.js process cannot execute graceful shutdown routines, write final log traces, or close database sockets.
The V8 Heap Mirage: Why --max-old-space-size Fails
Configuring --max-old-space-size to equal your Kubernetes container limit is the most widespread configuration error in cloud-native Node.js deployments. The V8 heap size flag only governs memory managed by the V8 garbage collector, which represents only a subset of total process memory.
+-----------------------------------------------------------------------------------+
| Total Node.js Resident Set Size (RSS) |
+-----------------------------------------------------------------------------------+
| [ V8 Managed Heap ] |
| - Old Space (Objects, closures) |
| - New Space / Nursery (Short-lived variables) |
| - Governed by: --max-old-space-size |
|-----------------------------------------------------------------------------------|
| [ Non-V8 Native Memory (UNTRACKED BY V8 GARBAGE COLLECTOR) ] |
| - Node.js Buffer instances (Allocated outside V8 via C++ malloc) |
| - Libuv threadpool stacks & socket buffers |
| - Native C++ addons (sharp, bcrypt, database drivers) |
| - V8 Code Space & Bytecode caches |
| - WebAssembly instances & SharedArrayBuffers |
+-----------------------------------------------------------------------------------+
Consider a Kubernetes deployment configured with:
resources:
limits:
memory: "1Gi"
requests:
memory: "512Mi"
If an engineer configures the container startup command as:
# FATAL CONFIGURATION: Guarantees Exit Code 137 under load
node --max-old-space-size=1024 server.js
The application will fail consistently under traffic. When the V8 old space reaches 900MB, the runtime may allocate an additional 150MB of native buffers to handle incoming HTTP payloads or gzip compression streams.
Total container memory reaches 1,050MB. Because the aggregate exceeds 1,024MB, the kernel kills the container immediately. The V8 garbage collector never had the opportunity to run a major scavenge or mark-sweep cycle because the heap itself had not yet breached its 1,024MB ceiling.
Sizing Formulas for Containerized Node.js
To prevent kernel evictions, you must calculate memory allocations using a tiered headroom formula based on official recommendations in the Kubernetes Resource Management documentation and the Node.js CLI documentation.
V8 Heap Ceiling = Container Memory Limit * 0.70
Native Buffer & OS Headroom = Container Memory Limit * 0.30
Reference Memory Allocation Matrix
| Container Limit (K8s) | Recommended --max-old-space-size | Allocated Headroom | Typical Workload Profile |
|---|---|---|---|
| 512 MiB | 350 (350 MB) | 162 MB (31%) | Lightweight microservices, webhook receivers |
| 1 GiB (1024 MiB) | 700 (700 MB) | 324 MB (31%) | Standard REST / GraphQL APIs with light transforms |
| 2 GiB (2048 MiB) | 1400 (1400 MB) | 648 MB (31%) | Heavy JSON transformations, reporting, SSR engines |
| 4 GiB (4096 MiB) | 2800 (2800 MB) | 1296 MB (31%) | Large in-memory caching, PDF/image manipulation |
When container limits are configured conservatively, V8 approaches its heap limit first. When old space utilization nears --max-old-space-size, V8 initiates aggressive generational garbage collection sweeps to reclaim unreferenced memory. If memory remains unrecoverable due to application memory leaks, Node.js throws a catchable JavaScript heap out of memory error (exit code 1) rather than suffering an uncatchable kernel SIGKILL (exit code 137).
Diagnosing OOMKilled Causes in Production
When investigating exit code 137, you must verify whether the pod was terminated due to a local container limit breach or an overall node-level memory exhaustion event.
Step 1: Inspect Pod Termination Diagnostics
Run kubectl describe pod against the failing pod:
kubectl describe pod order-service-789cf9b7-w2z9v -n production
Review the Last State block in the output:
Containers:
api:
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: OOMKilled
Exit Code: 137
Started: Mon, 09 Nov 2026 10:14:22 +0000
Finished: Mon, 09 Nov 2026 10:28:45 +0000
If Reason reads OOMKilled, the container directly violated its cgroup memory limit.
Step 2: Correlate Kernel Dmesg Events
Access the underlying Kubernetes node via SSH or a privileged debug pod and inspect kernel ring buffer logs:
dmesg -T | grep -E -i "oom[-_]killer|killed process"
[Mon Nov 09 10:28:45 2026] Memory cgroup out of memory: Kill process 284192 (node) score 985 or sacrifice child
[Mon Nov 09 10:28:45 2026] Killed process 284192 (node) total-vm:1894220kB, anon-rss:1042312kB, file-rss:4112kB, shmem-rss:0kB
[Mon Nov 09 10:28:45 2026] oom_reaper: reaped process 284192 (node), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
The kernel log explicitly states Memory cgroup out of memory. Notice that anon-rss (anonymous resident set size) was 1,042,312 kB (approximately 1,017 MB), confirming that the process breached its 1Gi cgroup boundary.
Step 3: Check for Node-Level Evictions
If kubectl describe pod shows Reason: Evicted with exit code 137, but the container states do not report OOMKilled, the physical node ran out of allocatable memory.
The kubelet eviction manager continuously monitors node thresholds like memory.available < 100Mi. When breached, the kubelet evicts pods based on their Quality of Service (QoS) class:
- BestEffort: Pods with no requests or limits defined are evicted first.
- Burstable: Pods where requests are lower than limits are evicted second.
- Guaranteed: Pods where requests strictly equal limits are evicted last.
Hardening Kubernetes Manifests for Node.js Services
Deploying resilient Node.js services requires configuring both container-level environment variables and declarative Kubernetes resource limits.
Production Deployment Manifest
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-service
namespace: production
labels:
app: order-service
spec:
replicas: 3
selector:
matchLabels:
app: order-service
template:
metadata:
labels:
app: order-service
spec:
containers:
- name: api
image: order-service:v2.4.1
command: ["node"]
args:
# 1. Enforce heap ceiling to 70% of the 1Gi container limit (716 MB)
- "--max-old-space-size=716"
- "dist/server.js"
env:
- name: NODE_ENV
value: "production"
resources:
# Guaranteed QoS Class: requests equal limits to protect against node eviction
requests:
cpu: "500m"
memory: "1Gi"
limits:
cpu: "1000m"
memory: "1Gi"
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 2
Setting requests.memory exactly equal to limits.memory grants the pod the Guaranteed Quality of Service class. Under node memory pressure, the kubelet will evict BestEffort and Burstable pods first, protecting your critical transaction pipelines from unnecessary restarts. Similar resource right-sizing strategies are detailed in our architectural guide to slashing cloud infrastructure costs.
The Buffer Leak Trap: Detecting Non-Heap Growth
If your container continues to encounter exit code 137 despite configuring --max-old-space-size to 70% of the limit, your application is likely leaking native non-heap memory.
Node.js manages native memory through Buffer.allocUnsafe(), streams, and C++ addon bindings. To locate native memory bloat, log detailed process memory distributions in your metrics exporter:
// metrics/memory-audit.ts
export function collectMemoryDistribution() {
const usage = process.memoryUsage();
return {
// Total memory allocated by the operating system for the process
rssMb: Math.round(usage.rss / (1024 * 1024)),
// V8 managed memory
heapTotalMb: Math.round(usage.heapTotal / (1024 * 1024)),
heapUsedMb: Math.round(usage.heapUsed / (1024 * 1024)),
// Native C++ allocations (Buffers, cryptographic contexts)
externalMb: Math.round(usage.external / (1024 * 1024)),
// ArrayBuffers and SharedArrayBuffers
arrayBuffersMb: Math.round(usage.arrayBuffers / (1024 * 1024)),
};
}
// Example production diagnostic check
setInterval(() => {
const mem = collectMemoryDistribution();
if (mem.externalMb > 250) {
console.warn(`[NATIVE MEMORY LEAK] External buffer memory exceeds threshold: ${mem.externalMb} MB`);
}
}, 30000);
Common Native Memory Culprits:
- Unbounded Stream Buffering: Reading incoming file uploads directly into memory using
fs.readFile()instead of streaming via pipeline pipes. - Global Event Listeners: Attaching listeners to
EventEmitterinstances without removing them when requests terminate, causing closures to retain large buffer references. - APM Agent Over-Instrumentation: Ingesting high-cardinality trace contexts in memory buffers, as outlined in our analysis of OpenTelemetry high-cardinality costs.
Production Engineering Runbook for Kubernetes Memory Health
To prevent exit code 137 from degrading service availability across your Kubernetes clusters:
- Configure Vertical Pod Autoscalers (VPA): Deploy VPA in
Recommendationmode across your staging clusters. VPA observes real-world resident set size under simulated peak load and suggests realistic memory requests and limits. - Audit Cgroup Version Compatibility: On Kubernetes 1.25 and newer running Linux kernel 5.8+, nodes use cgroups v2. Ensure your container base images use Node.js 18 or 20, which have native cgroups v2 memory limit detection built into the runtime.
- Establish Alerting on Memory Headroom: Do not wait for kernel SIGKILL events. Configure Prometheus alerts to fire when container memory usage reaches 85% of its limit for more than three minutes:
container_memory_working_set_bytes{container!="POD"} / container_spec_memory_limit_bytes > 0.85 - Engage an Architectural Diagnostic: When microservices suffer recurrent OOM terminations under production surges, leverage our 48-Hour Codebase Audit to analyze container resource limits, memory allocation profiles, and cluster scheduling boundaries.
Balancing V8 heap parameters against container cgroup limits ensures that your Node.js microservices survive traffic spikes without triggering catastrophic kernel terminations.
Elena Rostova
Product Strategy LeadProduct and operations lead dedicated to helping non-technical founders navigate technical scale and architectural decisions. Advises founders on technical debt triage, cloud unit economics, and rapid pre-launch risk evaluation.
What does Kubernetes Exit Code 137 mean?
Why does Node.js get OOMKilled before reaching --max-old-space-size?
What is the recommended ratio between V8 heap size and container memory limits?
How do you distinguish pod-level OOM from node-level memory pressure?
Have our team inspect your AI-generated codebase.
48-hour turnaround with direct pull requests fixing security and scale bottlenecks.