A Java service is OOMKilled at 2 GiB limit but the heap is only `-Xmx1800m`.
IntermediateTroubleshootingResources, OOM, probes and termination
Answer
Likely causes → The JVM uses much more than the heap: metaspace, thread stacks, code cache, direct buffers (Netty), GC structures. Heap 1.8 GiB plus 400+ MiB of native memory exceeds 2 GiB.
Diagnose →
kubectl exec api-x -- jcmd 1 VM.native_memory summary # needs -XX:NativeMemoryTracking=summary
kubectl exec api-x -- jcmd 1 GC.heap_info
Fix → Size the heap as a percentage of the cgroup limit instead of a fixed value:
env:
- name: JAVA_TOOL_OPTIONS
value: "-XX:MaxRAMPercentage=70 -XX:MaxDirectMemorySize=256m"
Leave 25–30% of the limit for non-heap memory.
Prevent → Use container-aware JVMs (JDK 17+), percentage-based sizing, and load-test at the production limit.
More on Resources, OOM, probes and termination
`kubectl describe pod` shows `Last State: Terminated, Reason: OOMKilled, Exit Code: 137`.BeginnerMany Pods on one node were killed at once and the node shows a `SystemOOM` event. Container limits were not reached.AdvancedPods show `Evicted` with `The node was low on resource: memory. Threshold quantity: 100Mi, available: 87Mi. Container app was using 1.4Gi, request is 256Mi`.IntermediateA Pod is evicted with `Pod ephemeral local storage usage exceeds the total limit of containers 1Gi`.Intermediatep99 latency spikes every few seconds, CPU usage graph shows only 40% of the limit.AdvancedPods restart every few minutes with `Liveness probe failed: Get "http://10.0.3.17:8080/healthz": context deadline exceeded (Client.Timeout exceeded while awaiting headers)`.Intermediate