<p>I'm running a spring boot inside a pod with the below configurations.</p>

<p>Pod limits:</p>

<pre><code>resources:
    limits:
      cpu: "1"
      memory: 2500Mi
    requests:
      cpu: "1"
      memory: 2500Mi
</code></pre>

<p>command args:</p>

<pre><code>spec:
containers:
- args:
  - -c
  - ln -sf /dev/stdout /var/log/access.log;java -Dcom.sun.management.jmxremote
    -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.ssl=false -Djava.security.egd=file:/dev/./urandom
    -Xms1600m -Xmx1600m -XX:NewSize=420m -XX............
</code></pre>

<ol>
<li>What happens if the java process has reached its max heap limit (i.e 1600m (Xmx1600m))</li>
<li>If Xmx has no effect on the java process inside a pod, it can go up to pod limit right (i.e. memory: 2500Mi of limits section)</li>
<li>If the above configurations are correct, then we are wasting 900Mi of memory right (2500-1600=900)</li>
</ol>

<p>The -Xmx flag only controls Java heap memory, which is space available for your own Java objects when running your code. If you run out, JVM will do garbage collection to make space. If you still ran out, you get an OutOfMemoryException thrown.</p>

<p>Java JVM also uses a bunch of other memory internally for stuff like loading classes, JIT compilation etc... Therefore you need to allow more memory in Kubernetes than just -Xmx value. If you exceed the Kubernetes limit value, then probably Java will crash.</p>

<p>The config you posted above looks fine. Normally I come to find these values by looking at the Kubernetes memory usage graph after running for some time without limits.</p>
