javadockerkuberneteswildfly

How add JAVA_OPTS variable to wildfly by kubernetes yaml file?


I'm trying to add new variable to JAVA_OPTS

Wildfly command in Dockerfile:

CMD cd /opt/wildfly/bin && ./standalone.sh -b="0.0.0.0"

Pod yaml file:

 env:
   - name: JAVA_OPTS
     value: -DattributeName=value

But the new attribute is not added to system properties and I see only default variables defined in standalone.conf:

JAVA_OPTS:  -server -Xms6g -Xmx6g -XX:MetaspaceSize=1536M -XX:MaxMetaspaceSize=1536M -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n -Duser.language=en -Duser.region=US -Dfile.encoding=UTF-8 -Dclient.encoding.override=UTF-8 -Ddefault.client.encoding=UTF-8 -Dorg.apache.catalina.connector.URI_ENCODING=UTF-8 -Dorg.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING=true -Djboss.as.management.blocking.timeout=6000 -Didit.system.placeholder

Any idea how set JAVA_OPTS by k8s yaml file? Thanks!


Solution

  • I extended the standard wildfly image by creating a Dockerfile containing:

    COPY standalone.conf /opt/wildfly/bin
    

    I added placeholder in standalone.conf for JAVA_OPTS added by kubernetes environment variable

    JAVA_OPTS="$JAVA_OPTS $DYNAMIC_JAVA_OPTS"
    

    Inject the parameter by k8s yaml

    env:
       - name: DYNAMIC_JAVA_OPTS
       value: -DattributeName=value