<p>My pod is running in k8s and restarts every 20-30 hours, caused by an <code>OOMKilled</code> error, here are the configured limits:</p>
<pre><code>  limits:
    cpu: 600m
    memory: 1536Mi
  requests:
    cpu: 150m
    memory: 1536Mi
</code></pre>
<p>In the container is a JVM (Spring Boot) running with the following Options:</p>
<pre><code>-Xms256m -Xmx1G -Xdebug -XX:+UseG1GC -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=26
</code></pre>
<p><strong>Analysis of the JVM Metrics</strong></p>
<p>From my point of view, I can see, that there is a load peak, but not high enough to reach the memory limits, however the CPU Usage increases rapidly:
<a href="https://i.stack.imgur.com/SRbds.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SRbds.png" alt="enter image description here" /></a></p>
<p><strong>Analysis of the Pod Metrics</strong></p>
<p>Let me show you the metrics of the pod provided by k8s:
<a href="https://i.stack.imgur.com/D8ZqM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D8ZqM.png" alt="enter image description here" /></a></p>
<p>Memory increases much more than in the JVM shows. CPU Throttling is active. But I do not find the root cause. It seems that the container reaches the Limits and not the JVM, but why? Can CPU throttling causes Memory issues? Throttling is an expected behavior for peaks to slow down. I do not expect any memory issues in that case.</p>

<p>It is possible for CPU throttling to indirectly cause memory issues by making garbage collection in the JVM less efficient or escalate an already inefficient memory usage, as such it may result in slower response times for your application, leading to more requests being queued up and more memory being used making the application store more objects in memory while waiting for requests to be processed.</p>
<p>The JVM flags that you have set are a good starting point. To further investigate any memory leaks you might want to use the followings to dump the heap on an OOM and analyze the dump with a tool like Java VisualVM to find the root cause.</p>
<pre><code>-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path/to/heapdump.bin
</code></pre>
<blockquote>
<p>Throttling is an expected behavior for peaks to slow down.</p>
</blockquote>
<p>Yes, but I would consider CPU throttling more of a handbrake here and not the only <em>solution</em>. Instead I would implement an appropriate mechanism (like rate limiting, request queuing, circuit breakers, or backpressure throttling) either in the application or at the load balancer/reverse proxy level to prevent queues from forming.</p>
