How to pass additional JAVA_OPTIONS and/or JAVA_ADVANCED_FLAGS to JVM for Shell Script/k8s delegate, and self-managed(on-prem) services

If you ever find yourself in a scenario where you need to pass additional options to the JVM of any of the Harness Java based services (Delegate, Manager, Verification Service, Learning Engine, and more), here is a quick rundown on how to accomplish this.

All of our services that run JVMs have an environment variable JAVA_OPTIONS, that we look for on startup. The method of adding content to JAVA_OPTIONS is going to vary depending on the type of service, which mainly applies to the several flavors of delegate versions, for example:

  1. Let’s say we need to increase the maximum JVM heap size for a standard Shell Script delegate, in this case we advise against modifying any of the delegate startup scripts, instead create a new script that sets the environment variable and then calls start.sh, for example, we want the JVM max heap size to be 8192 MB, raise the ulimit for open file descriptors, and call our script start_delegate.sh in the same directory:

#!/bin/bash

export JAVA_OPTS="-Xmx8192m"
ulimit -n 10000

./start.sh

This will ensure the delegate JVM heap size max is started at 8G as we requested when we call the script, just ensure you ‘chmod +x start_delegate.sh’ and call this script to start the delegate with these options.

  1. For a Kubernetes based delegate, passing JAVA_OPTIONS is as simple as editing the harness-delegate.yaml, and under environment variables, locate JAVA_OPTIONS, default it contains:

image

Add your additional parameters for the JVM and apply or re-apply the yaml to update the JVM options(note: this can also be achieved by editing the delegate statefulset).

  1. For nearly all services in our self-managed/on-premise version of Harness, you can edit the ConfigMap for the corresponding service to add the necessary options, although note there is a slight difference in the variable name for some services(eg; Manager, it is JAVA_ADVANCED_FLAGS=):

image

Saving the ConfigMap will invoke a restart of the Manager to startup with the new flags passed to the JVM, typically editing the ConfigMaps manually is going to be done for troubleshooting purposes. If you need/want this to be implemented long term, it is highly recommended to make these changes in the KOTS admin console.

2 Likes