Actually I'm using the jib-maven-plugin to create Docker container for my application. Then I'm going to deploy it to Google servers where we have a Kubernetes environment.
Actually we are playing with the java env. variables from the jib-maven-plugin's config (pom.xml):
<jvmFlags>
<jvmFlag>-XX:MinRAMPercentage=60.0</jvmFlag>
<jvmFlag>-XX:MaxRAMPercentage=80.0</jvmFlag>
<jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag>
<jvmFlag>-Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"</jvmFlag>
</jvmFlags>
Now we would like to move these configurations to our deployment yml file, we found something like:
env:
- name: JAVA_OPTS
value: "-XX:MinRAMPercentage=60.0 -XX:MaxRAMPercentage=90.0 -XX:+HeapDumpOnOutOfMemoryError"
...
resources:
limits:
memory: 512Mi
requests:
memory: 256Mi
but it seems that if we remove these configs from the jib-maven-plugin's config file and move them to the yml file they are simply not working. The container starts without having any effects of the mentioned settings.
We are using open JDK 11, that may be also important.
How it's possible to control the Java env. options from the deployment file?
Thank you so much for your help, have a nice day!
The problem is that you're setting JAVA_OPTS and not JDK_JAVA_OPTIONS.
JAVA_OPTS is used by some application servers like Tomcat, but the JDK itself uses JDK_JAVA_OPTIONS.
Therefore, a working Kubernetes yaml would be something like:
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
template:
metadata:
...
spec:
containers:
- name: ...
image: ...
env:
- name: JDK_JAVA_OPTIONS
value: -XX:MinRAMPercentage=60 -XX:MaxRAMPercentage=80 -XX:+HeapDumpOnOutOfMemoryError -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"
Just adding a bit to the other answer.
For those using Java 9+ (as with OP), both JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS (beware it's neither JAVA_TOOLS_OPTIONS, JAVA_TOOL_OPTS, nor JAVA_OPTS) will likely work in this use case to prepend options at runtime.
For those using Java 8, only JAVA_TOOL_OPTIONS will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With