<p>I'm struggling to understand why my Java application is slowly consuming all memory available to the pod causing Kubernetes to mark the pod as out of memory. The JVM (OpenJDK 8) is started with the following arguments:</p>

<pre><code>-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=2
</code></pre>

<p>I'm monitoring the memory used by the pod and also the JVM memory and was expecting to see some correlation e.g. after major garbage collection the pod memory used would also fall. However I don't see this. I've attached some graphs below:</p>

<p>Pod memory:
<a href="https://i.stack.imgur.com/YMw2q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YMw2q.png" alt="enter image description here"></a> 
Total JVM memory
<a href="https://i.stack.imgur.com/Qz2K4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qz2K4.png" alt="enter image description here"></a>
Detailed Breakdown of JVM (sorry for all the colours looking the same...thanks Kibana)
<a href="https://i.stack.imgur.com/aiOqv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aiOqv.png" alt="enter image description here"></a></p>

<p>What I'm struggling with is why when there is a significant reduction in heap memory just before 16:00 does the pods memory not also fall?</p>

<p>It looks like you are creating a pod with a resource limit of 1GB Memory.
You are setting <code>-XX:MaxRAMFraction=2</code> which means you are allocating 50% of available memory to the JVM which seem to match what you are graphing as <code>Memory Limit</code>.</p>

<p>JVM then reserves around 80% of that which is what you are graphing in <code>Memory Consumed</code>.</p>

<p>When you look at <code>Memory Consumed</code> you will not see internal garbage collection (as in your second graph), because that GC memory is released back to JVM but is still reserved by it.</p>

<p>Is it possible that there is a memory leak in your java application? it is possibly causing more memory to get reserved over time, until the JVM limit (512MB) is met and your pod gets OOM killed.</p>
