<p>I'm using spring boot 2.5.6 and I'm generating the docker image with the spring boot maven plugin.
I'm deploying the application using AWS EKS with nodes managed by fargate.</p>
<p>The plugin configuration is the following</p>
<pre><code>&lt;plugin&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
        &lt;excludes&gt;
            &lt;exclude&gt;
                &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
                &lt;artifactId&gt;lombok&lt;/artifactId&gt;
            &lt;/exclude&gt;
        &lt;/excludes&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;
</code></pre>
<p>The command I use to execute it is the following</p>
<pre><code>./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=my-image-name
</code></pre>
<p>When the application is deployed on AWS EKS, the application print the following data</p>
<pre><code>Setting Active Processor Count to 2
Adding $JAVA_OPTS to $JAVA_TOOL_OPTIONS
Calculated JVM Memory Configuration: 
    -XX:MaxDirectMemorySize=10M 
    -Xmx408405K 
    -XX:MaxMetaspaceSize=128170K 
    -XX:ReservedCodeCacheSize=240M 
    -Xss1M 
    (Total Memory: 1G, Thread Count: 250, Loaded Class Count: 20215, Headroom: 0%)
Enabling Java Native Memory Tracking
Adding 128 container CA certificates to JVM truststore
Spring Cloud Bindings Enabled
Picked up JAVA_TOOL_OPTIONS: 
    -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties 
    -XX:+ExitOnOutOfMemoryError 
    -XX:ActiveProcessorCount=2 
    -XX:+HeapDumpOnOutOfMemoryError 
    -XX:HeapDumpPath=&quot;/var/log/containers/heapDump.hprof&quot; 
    -XX:MaxDirectMemorySize=10M 
    -Xmx408405K 
    -XX:MaxMetaspaceSize=128170K 
    -XX:ReservedCodeCacheSize=240M 
    -Xss1M 
    -XX:+UnlockDiagnosticVMOptions 
    -XX:NativeMemoryTracking=summary 
    -XX:+PrintNMTStatistics 
    -Dorg.springframework.cloud.bindings.boot.enable=true
</code></pre>
<p>If I go inside the container and I run the command &quot;free -h&quot; I get the following output</p>
<pre><code>total mem  : 7.7G
used mem   : 730M
free mem   : 4.6G
shared     : 820K
buff/cache : 2.4G
available  
</code></pre>
<p>Why the -Xmx is filled with 400Mb only? And why the total memory is only 1Gb?</p>

Gavi
<p>Posting this out of comments for better visibility.</p>
<hr />
<p>An important thing to mention is when <code>free</code> command is run inside a pod's container, it shows all available memory on the node where this pod is scheduled and running.</p>
<p>At this point it's very important to have memory <code>resources</code> and <code>limits</code> for java applications since JVM memory allocation can be set incorrectly if it happens by the application.</p>
<hr />
<p>There are two main options for resource allocation (in this particular case is <code>memory</code>):</p>
<ul>
<li><p>requests (<code>spec.containers[].resources.requests.memory</code>) - kubernetes scheduler has to find a node which has requested amount of memory, not less than specified.</p>
<p>It's very important to set the <code>requests</code> reasonably since it's used for scheduling and there are chances that kubernetes scheduler won't be able to find a sufficient node with enough free memory to schedule the pod - <a href="https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#specify-a-memory-request-that-is-too-big-for-your-nodes" rel="nofollow noreferrer">good example of incorrect requests</a></p>
</li>
<li><p>limits (<code>spec.containers[].resources.limits.memory</code>) - kubelet insures that pod will not consume more than specified in limits, since containers in pod are allowed to consume more than requested.</p>
<p>It's also important to have <code>limits</code> set up for predictable resource consumption since containers can exceed requested memory and consume all node's memory until <code>OOM killer</code> is involved. <a href="https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/#if-you-do-not-specify-a-memory-limit" rel="nofollow noreferrer">Possible cases when limits are not set</a></p>
</li>
</ul>
