<p>I have a docker file which looks something like this:</p>
<blockquote>
<p>FROM openjdk:11</p>
<p>ADD target/test-1.0-SNAPSHOT.jar app.jar</p>
<p>ENTRYPOINT [&quot;java&quot;, &quot;-jar&quot;, &quot;/app.jar&quot;]</p>
</blockquote>
<p>My application is containerised and running inside a K8s pod. Now I read and understand that max heap size always takes 25% of the total pod memory. (for example, if pod resource is 2048Mi then 512 MB is your heap size allocated) I do not want this default behaviour of memory allocation rather I want a custom size to specify for my heap memory. Can anyone please tell me how to do that? I have tried passing the &quot;-Xms&quot; and &quot;-Xmx&quot; parameters as shown below in my docker file but it does not work?</p>
<blockquote>
<p>ENTRYPOINT [&quot;java&quot;,&quot;-Xms128M&quot;,&quot;-Xmx256M&quot;,&quot;-jar&quot;, &quot;/app.jar&quot;]</p>
</blockquote>

Ritesh Singh
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: &quot;Hello from the environment&quot;
    - name: DEMO_FAREWELL
      value: &quot;Such a sweet sorrow&quot;
    - name: JAVA_ARGS
      value: &quot;-Xmx1024M -Xms512M \&quot;
</code></pre>
<p>You can simply pass JAVA_ARGS to deployment yaml and you can limit usage of heap. The example is taken from kubernetes official page so it is node image but you can simply add JAVA_ARGS to environment variables.</p>
<p>Reference : <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/</a></p>
