Reputation: 223
I have a docker file which looks something like this:
FROM openjdk:11
ADD target/test-1.0-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
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 "-Xms" and "-Xmx" parameters as shown below in my docker file but it does not work?
ENTRYPOINT ["java","-Xms128M","-Xmx256M","-jar", "/app.jar"]
Upvotes: 0
Views: 2658
Reputation: 1573
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: "Hello from the environment"
- name: DEMO_FAREWELL
value: "Such a sweet sorrow"
- name: JAVA_ARGS
value: "-Xmx1024M -Xms512M \"
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.
Reference : https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
Upvotes: 2