is it possible to pass a function as the value in a K8s' pod command for evaluation? I am passing in JVM arguments to set the MaxRAM parameter and would like to read the cgroups memory to ascertain a value for the argument
This is an example of what I'm trying to do
- command:
- /opt/tools/Linux/jdk/openjdk1.8.0_181_x64/bin/java
- -XX:MaxRAM=$(( $(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) * 70/100 ))
Unfortunately the above doesn't work and fails with the following error:
Improperly specified VM option 'MaxRAM=$(( $(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) * 100 / 70 ))'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Is this doable? If so, what's the right way to do it? Thanks!
That is shell syntax so you need to run a shell to interpret it.
command:
- sh
- -c
- |
exec /opt/tools/Linux/jdk/openjdk1.8.0_181_x64/bin/java -XX:MaxRAM=$(( $(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) * 70/100 ))
Reasonably recent versions of the JVM have direct support for understanding the container memory limits. If you can update to at least Java 8u191 then it supports the current set of relevant JVM options. You can set:
- command:
- /opt/tools/Linux/jdk/openjdk1.8.0_251_x64/bin/java
- -XX:MaxRAMPercentage=70.0