Hi Team,
I have a question:
Can anyone give-me a full example of this issue: https://github.com/GoogleContainerTools/jib/issues/1592
I trie to deploy my jib-api on kubernetes, but in my workspace we use JAVA_OPTS on kubernetes deployment, like this:
- name: JAVA_OPTS
value: -noverify -XX:TieredStopAtLevel=1 -XshowSettings:vm -XX:MaxRAMPercentage=55
-XX:InitialRAMPercentage=50 -XX:MinRAMPercentage=30 -XX:+UseContainerSupport
I can't understand the JAVA_OPTIONS_TOOLS, like FAQ example, or how i configure these variable on POM.
Thanks !
I don't think I understand your problem. However, what our FAQ says is that instead of JAVA_OPTS you should use JAVA_TOOL_OPTIONS
If you would like to configure them in your pom. Use the jvmFlags option as seen in this example: https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#example
@loosebazooka , thats the point.
I want to configure my java_opts like a variable, you know? I want to resolve this variable with the value configured on my kubernetes deployment, at runtime.
<container>
<ports>8080</ports>
<jvmFlags>$JAVA_OPTS</jvmFlags>
</container>
Anything like this
So if you use the default base image distroless/java, it does not have a shell, so it cannot do shell expansion so you can't do $JAVA_OPTS because it wont expand it. There are multiple way to start your app with shell expansion, but you will need to use a custom base image (that has a shell) and custom entrypoint. See docker docs for shell vs exec. This behavior is, however, not built into jib.
Under the default configuration the only way to configure runtime jvm args is by using JAVA_TOOL_OPTIONS as described in the faq.
I'm use a custom base image...
Today i have a pipeline and I use a dockerfile to pack my container_image, using a entrypoint:
- ENTRYPOINT exec java $PROFILE $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar
With this, i can use JAVA_OPTS on Kubernetes (I do this because I have a third centralized system where developers can configure their properties. After this, my system update configurations on kubernetes .
If i need use JAVA_TOOLS_OPTS, how can i set this on my POM? FAQ have a kubernetes side (deployment) example.
oh I see: JAVA_TOOL_OPTIONS is automatically picked up by java, you do not have to specify it on the command line. As long as the environment variable is defined, it will incorporate it.
I have to say it is JAVA_TOOL_OPTIONS, not
JAVA_TOOLS_OPTIONS (wrong)
JAVA_TOOL_OPTS (wrong)
JAVA_TOOLS_OPTS (wrong)
JAVA_OPTIONS_TOOLS (wrong)
Most of the JVMs I know will honor JAVA_TOOL_OPTIONS. The Oracle JDK/OpenJDK will print out the message that the environment variable is picked up:
$ JAVA_TOOL_OPTIONS=-Xmx1024m java -Xms256m -Xmx512m -version
Picked up JAVA_TOOL_OPTIONS: -Xmx1024m
openjdk version "1.8.0_212"
...
Ok, let me see:
Thanks !!
You already know how to set environment variables on Kubernetes.
- name: JAVA_OPTS
value: -noverify -XX:TieredStopAtLevel=1 -XshowSettings:vm -XX:MaxRAMPercentage=55
-XX:InitialRAMPercentage=50 -XX:MinRAMPercentage=30 -XX:+UseContainerSupport
So, I think you can do
- name: JAVA_OPTS
value: -noverify -XX:TieredStopAtLevel=1 -XshowSettings:vm -XX:MaxRAMPercentage=55
-XX:InitialRAMPercentage=50 -XX:MinRAMPercentage=30 -XX:+UseContainerSupport
- name: JAVA_TOOL_OPTIONS
value: ...
And yes, you don't change your POM. Most JVMs by their design will pick it up, as shown in the example https://github.com/GoogleContainerTools/jib/issues/1833#issuecomment-510238427.
You may want to reconcile the use of JAVA_OPTS and JAVA_TOOL_OPTIONS though. Find out who
is making use of JAVA_OPTS and where. I know some popular server startup/shutdown scripts (like Tomcat) and some Java tools make explicit use of it.
It's works man !!!
Great !!
But two options in my case doesn't work, like:
-noverify ;
-XshowSettings:vm
Do you know any documented limitation using JAVA_TOOL_OPTIONS ?
I think it's occur because i'm testing (openjdk) java1.12
Some Oracle doc: https://docs.oracle.com/en/java/javase/11/troubleshoot/environment-variables-and-system-properties.html#GUID-BE6E7B7F-A4BE-45C0-9078-AA8A66754B97
It says
Since this environment variable is examined at the time that
JNI_CreateJavaVMis called, it cannot be used to augment the command line with options that would normally be handled by the launcher, ...
That is, I can't say for sure, but it might be that -XshowSettings:vm is an option defined by the launcher at the front, not the JVM itself? Maybe for those two, pass them in the command line as before?
Now I have tested with java1.11, but show me the same result..
Yeas, is an option.
-noverify -XX:TieredStopAtLevel=1 -XshowSettings:vm -XX:+UseContainerSupport
These parameters are static (normaly) in my APIs, so i can use on JVM_FLAGS in jib. But, It's strange that -XX:TieredStopAtLevel=1 works fine ... But ok ...
Man, so thanks, you're the best!!
Glad it works. I'll close the issue.
BTW, I believe -XX:+UseContainerSupport is unnecessary (true by default) for Java >= 9 and for latest Java 8 JVMs (>= 8u191).
https://blog.softwaremill.com/docker-support-in-new-java-8-finally-fd595df0ca54
Most helpful comment
I have to say it is
JAVA_TOOL_OPTIONS, notJAVA_TOOLS_OPTIONS(wrong)JAVA_TOOL_OPTS(wrong)JAVA_TOOLS_OPTS(wrong)JAVA_OPTIONS_TOOLS(wrong)Most of the JVMs I know will honor
JAVA_TOOL_OPTIONS. The Oracle JDK/OpenJDK will print out the message that the environment variable is picked up: