A Java pod keeps getting OOMKilled at its 2Gi limit, even though `-Xmx2g` is set and the heap graph never reaches 2 GB.
IntermediateTroubleshootingDisk, memory and CPU
Answer
Likely causes → The heap is only part of JVM memory. Metaspace, thread stacks, code cache, direct buffers (Netty), and GC structures sit on top of -Xmx. A 2 GB heap in a 2 Gi container guarantees the cgroup limit is crossed.
Diagnose →
kubectl describe pod billing-7d9 | grep -A3 'Last State'
kubectl exec billing-7d9 -- jcmd 1 VM.native_memory summary # needs -XX:NativeMemoryTracking=summary
Fix → Size the heap as a fraction of the container limit instead of a fixed -Xmx:
JAVA_TOOL_OPTIONS="-XX:MaxRAMPercentage=70 -XX:MaxDirectMemorySize=256m"
Leave 25–30% of the limit for non-heap memory, or raise the limit.
Prevent → Standardise JVM flags in the base image, and alert on container working set above 90% of the limit before the kill happens.
More on Disk, memory and CPU
The app fails to write with "No space left on device", but `df -h` shows the volume is only 40% used.Beginner`df -h` says `/` is 100% full, but `du -sh /*` only adds up to 30% of the disk.BeginnerA server shows load average 40 on 8 cores, but `top` shows CPU 60% idle and the app is crawling.BeginnerPods are being evicted with "The node was low on resource: ephemeral-storage. Container app was using 18Gi, which exceeds its request of 0."IntermediateCI build agents running Docker fail with "no space left on device" while pulling images; `/var/lib/docker` is 95% full.IntermediatePostgres on a VM died overnight; `dmesg` shows "Out of memory: Killed process 2314 (postgres) total-vm:..., anon-rss:...".Intermediate