<p>After learning about arguments that can be passed to a Java 8 Virtual Machine to make it container-aware (i.e. -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap), I am trying to add these arguments to my Kubernetes deployment for a Spring Boot service.</p>

<p>In containers section of my deployment YAML file, I have the following:<p></p>

<pre>

    resources:
        requests:
            memory: "256Mi"
            cpu: "50m"
        limits:<br/>
            memory: "512Mi"
            cpu: "200m"
    env:
    - name: JVM_OPTS
      value: "-Xms256M -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1"

</pre>

<p>In my Dockerfile, I have:</p>

<pre>

    ENV JVM_OPTS="-Xmx256M"
    ENV JVM_ARGS="-Dspring.profiles.active=kubernetes"
    EXPOSE 8080
    ENTRYPOINT [ "sh", "-c", "java $JVM_ARGS $JVM_OPTS -jar testservice.jar" ]

</pre>

<p>I can't seem to figure out why the max heap sized does not get sized properly:</p>

<pre>
$ kubectl exec test-service-deployment-79c9d4bd54-trxgj -c test-service -- java -XshowSettings:vm -version'
VM settings:
    Max. Heap Size (Estimated): 875.00M
    Ergonomics Machine Class: server
    Using VM: OpenJDK 64-Bit Server VM

openjdk version "1.8.0_171"
OpenJDK Runtime Environment (IcedTea 3.8.0) (Alpine 8.171.11-r0)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
</pre>

<p>What am I doing wrong here?</p>

<p>On a local Docker install, I can see the JVM max heap set correctly: </p>

<pre>
$ docker run openjdk:8-jre-alpine java -Xms256M -Xmx512M -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -XshowSettings:vm -version
VM settings: 
    Min. Heap Size: 256.00M 
    Max. Heap Size: 512.00M 
    Ergonomics Machine Class: server 
    Using VM: OpenJDK 64-Bit Server VM 

openjdk version "1.8.0_171" 
OpenJDK Runtime Environment (IcedTea 3.8.0) (Alpine 8.171.11-r0) 
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
</pre>

<p>When running <code>java -XshowSettings:vm -version</code> in container, <code>JVM_OPTS</code> is not include in your command.</p>

<p>Try with this one</p>

<pre><code>kubectl exec test-service-deployment-79c9d4bd54-trxgj -c test-service \
          -- sh -c 'java $JVM_OPTS -XshowSettings:vm -version'
</code></pre>
