2

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
gsdk
  • 57
  • 2
  • 8
  • I am not sure if I good understood you, could you elaborate?. When you are using `--set`, you just set specific. If you want set multiple values you should use comma like here: https://stackoverflow.com/questions/48316330/how-to-set-multiple-values-with-helm or `--set-string`. Helm is based on `values.yaml`. – PjoterS Mar 27 '20 at 17:35

1 Answers1

3

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
wpnpeiris
  • 766
  • 4
  • 14