Memory usage of a Java service in a pod is much higher than the heap. How do you size it?
AdvancedScenarioResources, autoscaling and scheduling
Answer
Situation read → The pod is OOMKilled although -Xmx is 2g and the limit is 2.5g.
What I'd do →
- Remember JVM memory includes metaspace, thread stacks, direct buffers and code cache
- Set
-XX:MaxRAMPercentage=70instead of a fixed Xmx - Set the limit with 30% headroom
- Check usage with
kubectl topand JVM NMT - Use
kubectl describe podto confirmReason: OOMKilled, exit code 137
Why → Container limits include all process memory, not just heap.
Interview tip → Mention container-aware JVMs since version 10.
More on Resources, autoscaling and scheduling
How do you choose requests and limits for a new service?BeginnerPods are Pending with `0/6 nodes are available: 6 Insufficient cpu`. What do you do?IntermediateExplain QoS classes and which pods get evicted first.IntermediateCPU limits cause latency spikes though average usage is low. Why and what is the fix?IntermediateHow do you configure an HPA on CPU?BeginnerHPA shows `<unknown>/70%` for CPU. What do you do?Intermediate