I see that you used OpenJDK Alpine to deploy a JAVA application, so you need to use this environment "JAVA_TOOL_OPTIONS" instead of "JAVA_OPTS", something like:

spec:
  containers:
  - name: jvm_options
    image: xxx:xxx
    env:
    - name: JAVA_TOOL_OPTIONS
      value: "-Xmx768m -XX:MaxMetaspaceSize=256m"

Once your application is running, you can check the application log and you will find the log below:

Picked up JAVA_TOOL_OPTIONS: -Xmx768m -XX:MaxMetaspaceSize=256m
Answer from HKBN-ITDS on Stack Overflow
🌐
DEV Community
dev.to › azure › a-better-way-to-tune-the-jvm-in-dockerfiles-and-kubernetes-manifests-329c
A Better Way to Tune the JVM in Dockerfiles and Kubernetes Manifests - DEV Community
September 12, 2025 - containers: - name: myapp image: myapp:latest env: - name: JDK_JAVA_OPTIONS value: "-Xmx512m -XX:+UseG1GC" Your deployment YAML stays clean and your operations team can tune JVM behavior at deploy time without changing the image. ✅ Cleaner Manifests – fewer arguments to maintain 🔄 Configurable at Runtime – no rebuild required 🛠 Debug-Friendly – JVM prints the options it picked up 🐳 Perfect for Containers – works across Docker, Kubernetes, ECS, etc. 🎯 Applies to All JDK Tools – not just java, but also javac, jshell, etc.
🌐
GitHub
github.com › GoogleContainerTools › jib › issues › 1833
Questions around environment variables ($JAVA_TOOL_OPTIONS) · Issue #1833 · GoogleContainerTools/jib
July 10, 2019 - I trie to deploy my jib-api on ... 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 ...
Author   GoogleContainerTools
Discussions

appending additional options to JAVA_TOOL_OPTIONS at runtime
Now while running the myservice container in kubernetes, I want to provide additional option "-DSERVICE_NAME=ia" using: env: - name: JAVA_TOOL_OPTIONS value: "-DSERVICE_NAME=ia" More on github.com
🌐 github.com
0
June 4, 2024
docker - Passing java_opts to spring boot applications in kubernetes - Stack Overflow
Currently, we are building Docker images with an entrypoint and passing this image to a Kubernetes deployment. Is there any way to pass the entrypoint directly to Kubernetes dynamically so that it More on stackoverflow.com
🌐 stackoverflow.com
Kubernetes args with java options
Hello, everyone! I’m not good at kubernetes and I’m trying to figure out how to work with this. Currently I am working with java application and I’m going to deploy it witin container. I have prepared Docker file with ENTRYPOINT ["java", "-jar", "java_j.jar"] in my java application. More on discuss.kubernetes.io
🌐 discuss.kubernetes.io
1
1
March 27, 2025
Java options within Kubernetes container - Stack Overflow
Finally: note that the standard ... between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11? You could just set this environment variable without trying to reconstruct command:. (IME if you have a choice, managing Kubernetes manifests tends to be easier if you can ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Overops
doc.overops.com › docs › attach-to-a-jvm-in-a-kubernetes-container
JVM in a Kubernetes Container - Introduction to OverOps
env: - name: TAKIPI_COLLECTOR_HOST value: "overops-collector-service" - name: TAKIPI_COLLECTOR_PORT value: "6060" - name: TAKIPI_RESOURCES_DIR value: "/tmp" - name: JAVA_TOOL_OPTIONS value: "-agentpath:/takipi/lib/libTakipiAgent.so" volumeMounts: - mountPath: /takipi name: takipi-volume volumes: - name: takipi-volume
🌐
GitHub
github.com › orgs › paketo-buildpacks › discussions › 259
Environment Variables in JAVA_TOOL_OPTIONS · paketo-buildpacks · Discussion #259
The image is deployed on a kubernetes cluster, which injects all necessary environmental variables in the pod at deployment time. I am trying to specify a couple of system properties, whose values need to be picked up from environment variables at startup, like so: JAVA_TOOL_OPTIONS=-Dexample.sys.prop=${EXAMPLE_SYS_PROP}
🌐
CNCF
cncf.io › blog › 2021 › 04 › 09 › add-java-agents-to-existing-kubernetes-and-helm-applications-instantly-2
Add Java agents to existing Kubernetes and Helm applications instantly | CNCF
June 5, 2022 - In that previous blog post, Josh demonstrated how to edit an existing Kubernetes application manifest to add a Java agent. The first step is to add an init container that will add the Java agent jar file to the pod’s filesystem. The second step is to add the JAVA_TOOL_OPTIONS environment variable with the -javaagent flag, instructing the JVM to load it.
Find elsewhere
🌐
GitHub
github.com › GoogleContainerTools › distroless › issues › 1605
appending additional options to JAVA_TOOL_OPTIONS at runtime · Issue #1605 · GoogleContainerTools/distroless
June 4, 2024 - Now while running the myservice container in kubernetes, I want to provide additional option "-DSERVICE_NAME=ia" using: env: - name: JAVA_TOOL_OPTIONS value: "-DSERVICE_NAME=ia"
Author   GoogleContainerTools
🌐
Medium
medium.com › @kaustubha.m › live-debug-of-java-springboot-microservices-on-kubernetes-3bd70f61a893
Live Debug of Java Springboot Microservices on Kubernetes | by Kaustubha M | Medium
October 29, 2024 - But, if the service cannot be debugged using above steps, then Live debug of services has to be performed by connecting to the Kubernetes Cluster. ... env: - name: JAVA_TOOL_OPTIONS value: "-agentlib:jdwp=transport=dt_socket,address=*:5555,server=y,suspend=n"
🌐
Elastic
elastic.co › observability-labs › blog › using-the-otel-operator-for-injecting-java-agents
Zero config OpenTelemetry auto-instrumentation for Kubernetes Java applications — Elastic Observability Labs
July 11, 2024 - The environment includes the explicit values defined in the env, as well as some implicit OpenTelemetry values (see the OpenTelemetry Operator for Kubernetes documentation for full details). ... and adds the environment variable JAVA_TOOL_OPTIONS=-javaagent:/otel-auto-instrumentation-java/javaagent.jar.
🌐
Kubernetes
discuss.kubernetes.io › general discussions
Kubernetes args with java options - General Discussions - Discuss Kubernetes
March 27, 2025 - Hello, everyone! I’m not good at kubernetes and I’m trying to figure out how to work with this. Currently I am working with java application and I’m going to deploy it witin container. I have prepared Docker file with ENTRYPOINT ["java", "-jar", "java_j.jar"] in my java application.
🌐
Medium
medium.com › @ajeet_ › optimizing-java-memory-management-heap-size-in-kubernetes-avoiding-out-of-memory-errors-e4da3a7c8fab
Optimizing Java Memory Management(Heap-size) in Kubernetes: Avoiding Out of Memory Errors | by Ajeet | Medium
January 9, 2025 - apiVersion: v1 kind: Pod metadata: name: my-java-pod spec: containers: - name: my-java-container image: <your-java-image> command: ["sleep", "infinity"] resources: limits: memory: "2Gi" # Example memory limit for the pod env: - name: JAVA_TOOL_OPTIONS value: "-XX:MaxRAMPercentage=50.0" Ensure you set appropriate memory requests and limits for your container. The JVM will calculate the heap size based on the available memory, and the -XX:MaxRAMPercentage=50.0 option will allocate 50% of the available memory to the heap. Apply the deployment configuration to your Kubernetes cluster using the following command:
🌐
Contrastsecurity
support.contrastsecurity.com › hc › en-us › articles › 4402067193364-Java-agent-with-Kubernetes
Manually install Java agent with Kubernetes – Contrast Security Support Portal
ENV JAVA_TOOL_OPTIONS='-javaagent:/opt/contrast/contrast.jar' For more details on adding the Contrast agent to your application/image. See our docker guide on the subject. In your terminal, navigate to the cloned repo's folder and run the following command to build the docker image. ... Tag and push your image to a local or public repo. docker tag spring-petclinic:k8s example/spring-petclinic:k8s ... Now this image can be used in the kubernetes deployment.
Top answer
1 of 2
2

In your Helm chart, you need to split out the different low-level JVM settings into individual items in the command: list. The easiest way to do this is to make the Helm-level settings be a list of options, and then you can iterate over it.

# values.yaml
jvmOptions:
  - -XX:UseSerialGC
  - -Xmx256m
  - -XX:MetaspaceSize=64m
# templates/deployments.yaml
         command:
           - java
{{- range .Values.jvmOptions }}
           - {{ toJson . }}
{{- end }}
           - -jar
           - java_j.jar

Since .Values.jvmOptions is a list here, the template range construct loops through it, setting . to each item in turn. In the example here, I use the toJson extension function to ensure each item is properly quoted as a string that fits on a single line.

Nothing would stop you from having multiple lists of option settings that you combined this way.

If you really want the JVM options as a space-separated string, then you need to split that string into words. There is a splitList extension function (not mentioned in the Helm documentation but it's there) that can do this.

# values.yaml
jvmOptions: "-XX:UseSerialGC -Xmx256M -XX:MetaspaceSize=64m"
# templates/deployments.yaml
         command:
           - java
{{- range splitList " " .Values.jvmOptions }}
           - {{ toJson . }}
{{- end }}
           - -jar
           - java_j.jar

The template part looks almost identical except for adding splitList in. Note that this is a fairly naïve splitting; there's not going to be any support for quoting or embedding spaces inside a single option or any non-space whitespace.

Finally: note that the standard JVMs do support passing options in environment variables; see for example What is the difference between JDK_JAVA_OPTIONS and JAVA_TOOL_OPTIONS when using Java 11? You could just set this environment variable without trying to reconstruct command:. (IME if you have a choice, managing Kubernetes manifests tends to be easier if you can set environment variables as opposed to using command-line options.)

# values.yaml
jvmOptions: "-XX:UseSerialGC -Xmx256M -XX:MetaspaceSize=64m"
# templates/deployments.yaml
         env:
{{- with .Values.jvmOptions }}
           - name: JDK_JAVA_OPTIONS
             value: {{ toJson . }}
{{- end }}
2 of 2
0

According to the Kubernetes docs, split the command array and the arguments array into command and args sections.

When you create a Pod, you can define a command and arguments for the containers that run in the Pod. To define a command, include the command field in the configuration file. To define arguments for the command, include the args field in the configuration file. The command and arguments that you define cannot be changed after the Pod is created.

The command and arguments that you define in the configuration file override the default command and arguments provided by the container image. If you define args, but do not define a command, the default command is used with your new arguments.

spec:
  containers:
    - name: test-java-service
      image: <your_image_name_here>
      command:
        - java
      args:
        - {{ .Values.TEST_JAVA_MEMORY_OPTS | quote }}
        - {{ .Values.TEST_JAVA_OPTS | quote }}
        - "-jar"
        - java_j.jar

When Helm populates values, don't specify the quotes yourself, or else the values replacement string will be interpreted literally as that string. Instead, pipe the Helm value to quote. Place quotes around any value that could be interpreted specially in YAML, such as values with - characters, like your Java options.

🌐
GitHub
github.com › bmuschko › gradle-docker-plugin › issues › 853
provide JAVA_OPTS environment variable for later configuration during deployment · Issue #853 · bmuschko/gradle-docker-plugin
September 5, 2019 - An option is missing to provide jvmargs to the java process of the docker image during deployment time eg in kubernetes. ... JAVA_TOOL_OPTIONS can be used to provide these parameters to the java process via a environment variable, but it might ...
Author   bmuschko
🌐
Java Code Geeks
javacodegeeks.com › home
JDK_JAVA_OPTIONS vs JAVA_TOOL_OPTIONS - Java Code Geeks
March 19, 2025 - Cloud/Docker – avoid long command-line options in Kubernetes or Docker. In this article, I compared the JVM options configuration between JDK_JAVA_OPTIONS vs JAVA_TOOL_OPTIONS via CLI examples.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › guides › troubleshoot › envvars002.html
The JAVA_TOOL_OPTIONS Environment Variable
April 21, 2026 - When this environment variable ... argument. This environment variable allows you to specify the initialization of tools, specifically the launching of native or Java programming language agents using the -agentlib or -javaagent options....
🌐
Piotr's TechBlog
piotrminkowski.com › home › best practices for java apps on kubernetes
Best Practices for Java Apps on Kubernetes - Piotr's TechBlog
February 2, 2024 - Should we set limits for Java apps on Kubernetes or not? The answer seems to be obvious. There are many tools that validate your Kubernetes YAML manifests, and for sure they will print a warning if you don’t set CPU or memory limits. However, there are some “hot discussions” in the community about that.