<p>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.</p>

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

<p>Similarly, my prod variables would something like </p>

<pre><code>"-Dapp1.url=http://prod.app1.xyz -Dapp2.url=http://prod.app2.abc ..."
</code></pre>

<p>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</p>

<pre><code>helm install my-app --set env=prod ./test-chart
</code></pre>

<p>or </p>

<pre><code>helm install my-app --set env=dev ./test-chart
</code></pre>

<p>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. </p>

<p>Example:</p>

<p>deployment.yaml</p>

<pre><code>spec:
    containers:
        env:
           - name: SYSTEM_OPTS
           - value: "{{ .Values.opts }}"
</code></pre>

<p>values-dev.yaml</p>

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

<p>values-prod.yaml</p>

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

<p>Then specify the related value file in the helm command.</p>

<p>For example, deploying on dev enviornemnt.</p>

<pre><code>helm install -f values-dev.yaml my-app ./test-chart
</code></pre>
