<p>I am currently deploying my applications in a Kubernetes cluster using Helm. Now I also need to be able to modify some parameter in the values.yaml file for different environments.</p>

<p>For simple charts with only one level this is easy by having different values-local.yaml and values-prod.yaml and add this to the <code>helm install</code> flag, e.g. <code>helm install --values values-local.yaml</code>. </p>

<p>But if I have a second layer of subcharts, which also need to distinguish the values between multiple environments, I cannot set a custom values.yaml.</p>

<p>Assuming following structure:</p>

<pre><code>| chart
   | Chart.yaml
   | values-local.yaml
   | values-prod.yaml
   | charts
      | foo-app
         | Chart.yaml
         | values-local.yaml
         | values-prod.yaml
         | templates
            | deployments.yaml
            | services.yaml
</code></pre>

<p>This will not work since Helm is expecting a <code>values.yaml</code> in subcharts.</p>

<p>My workaround right now is to have an if-else-construct in the subchart/values.yaml and set this in as a global variable in the parent values.yaml.</p>

<pre><code>*foo-app/values.yaml*
    {{ - if .Values.global.env.local }}
        foo-app:
          replicas: 1
    {{ else if .Values.global.env.dev}}
        foo-app:
          replicas: 2
    {{ end }}
</code></pre>

<hr>

<pre><code>parent/values-local.yaml
global:
  env:
   local: true

parent/values-prod.yaml
global:
  env:
   prod: true
</code></pre>

<p>But I hope there is a better approach around so I do not need to rely on these custom flags.</p>

<p>I hope you can help me out on this.</p>

<p>Here is how I would do it (for reference <a href="https://docs.helm.sh/chart_template_guide/#overriding-values-from-a-parent-chart" rel="noreferrer" title="overriding values">overriding values</a>):</p>

<ol>
<li>In your child charts (foochart) define the number of replicas as a variable:

<ul>
<li>foochart/values.yaml</li>
</ul></li>
</ol>

<pre><code>
...
replicas: 1
...
</code></pre>

<ul>
<li>foochart/templates/deployment.yaml</li>
</ul>

<pre><code>
...
spec:
  replicas: {{ .Values.replicas }}
...
</code></pre>

<ol start="2">
<li><p>Then, in your main chart's values files:</p>

<ul>
<li>values-local.yaml</li>
</ul></li>
</ol>

<pre><code>
foochart:
  replicas: 1
</code></pre>

<ul>
<li>values-prod.yaml</li>
</ul>

<pre><code>
foochart:
  replicas: 2
</code></pre>
