🇪🇸 Cambiar a versión en español: Calculadora de Memoria, Heap y Límites Anti-OOMKill en Kubernetes
Right-size Kubernetes requests.memory, limits.memory, and runtime Heap ceilings (-Xmx / --max-old-space-size) to eliminate surprise OOMKilled (Exit Code 137) crashes and Linux CFS CPU throttling stalls.
limits.memory1536 MiBcgroup v2 Accounting Formula & Non-Heap Overhead
Following Kubernetes Resource Management for Pods and Containers, Linux cgroups tracks total RSS + anonymous allocations + active page cache against limits.memory — not just language heap size:
Container Memory Budget = Observed Working Set × Non-Heap Multiplier + Multi-Worker Overhead + Spike Buffer
Safe Runtime Heap Cap = limits.memory × Safety Ratio (70% JVM, 75% Node.js, 85% Go GOMEMLIMIT)
Kubernetes QoS & Resource Limits Comparison
| Config Pattern | QoS Class | Node Pressure Behavior | Production Guidance |
|---|---|---|---|
requests.memory == limits.memory | Guaranteed | Last to be evicted by Kubelet | Best for critical APIs, caches, steady workloads |
Set requests.cpu, omit limits.cpu | Burstable (CPU) | Zero artificial CFS 100ms quota throttling on idle cores | Preferred for low P99 tail-latency web services |
-Xmx equal to limits.memory | Any | Exit Code 137 (OOMKilled) via Metaspace & stacks | Anti-pattern: keep 20–30% native headroom |
Frequently Asked Questions
Why do Kubernetes Pods die with OOMKilled (Exit Code 137) when JVM or Node heap still shows free space?
Linux cgroups counts everything inside the container namespace: JVM Metaspace, off-heap DirectByteBuffers, thread stacks (~1 MiB per thread), glibc arenas, and native C++ extensions. Setting heap size equal to limits.memory guarantees sudden kills under load.
Should I set strict limits.cpu on latency-sensitive microservices?
Not always. Linux CFS quota enforces CPU limits in 100ms slices; a short multi-threaded burst can exhaust a pod's quota in 15ms and freeze threads for the remaining 85ms even when node CPU sits idle.
container_memory_working_set_bytes metrics under load; see official Kubernetes Resource Management docs.