简体   繁体   中英

How to set java environment variables in a helm chart?

What is the best practice to set environment variables for a java app's deployment in a helm chart so that I can use the same chart for dev and prod environments? I have separate kubernetes deployments for both the environments.

spec:
    containers:
        env:
           - name: SYSTEM_OPTS
           - value: "-Dapp1.url=http://dev.app1.xyz -Dapp2.url=http://dev.app2.abc ..."

Similarly, my prod variables would something like

"-Dapp1.url=http://prod.app1.xyz -Dapp2.url=http://prod.app2.abc ..."

Now, how can I leverage helm to write a single chart but can create separated set of pods with different properties according to the environment as in

helm install my-app --set env=prod ./test-chart

or

helm install my-app --set env=dev ./test-chart

The best way is to use single deployment template and use separate value file for each environment. It does not need to be only environment variable used in the application. The same can be apply for any environment specific configuration.

Example:

deployment.yaml

spec:
    containers:
        env:
           - name: SYSTEM_OPTS
           - value: "{{ .Values.opts }}"

values-dev.yaml

# system opts
opts: "-Dapp1.url=http://dev.app1.xyz -Dapp2.url=http://dev.app2.abc "

values-prod.yaml

# system opts
opts: "-Dapp1.url=http://prod.app1.xyz -Dapp2.url=http://prod.app2.abc "

Then specify the related value file in the helm command.

For example, deploying on dev enviornemnt.

helm install -f values-dev.yaml my-app ./test-chart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM