<p>I'm learning Helm to setup my 3 AWS EKS clusters - sandbox, staging, and production.</p>
<p>How can I set up my templates so some values are derived based on which cluster the chart is being installed at? For example, in my <code>myapp/templates/deployment.yaml</code> I may want</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  ...
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
</code></pre>
<p>I may want <code>replicas</code> to be either <code>1</code>, <code>2</code>, or <code>4</code> depending if I'm installing the chart in my <code>sandbox</code>, <code>staging</code>, or <code>production</code> cluster respectively? I wanna do same trick for cpu and memory requests and limits for my pods for example.</p>
<p>I was thinking of having something like this in my <code>values.yaml</code> file</p>
<pre><code>environments:
  - sandbox
  - staging
  - production
perClusterValues:
  replicas:
    - 1
    - 2
    - 4
  cpu:
    requests:
      - 256m
      - 512m
      - 1024m
    limits:
      - 512m
      - 1024m
      - 2048m
  memory:
    requests:
      - 1024Mi
      - 1024Mi
      - 2048Mi
    limits:
      - 2048Mi
      - 2048Mi
      - 3072Mi
</code></pre>
<p>So if I install a helm chart in the <code>sandbox</code> environment, I want to be able to do</p>
<pre><code>$ helm install myapp myapp --set environment=sandbox

apiVersion: apps/v1
kind: Deployment
metadata:
  ...
spec:
  {{- if not .Values.autoscaling.enabled }}
  # In pseudo-code, in my YAML files
  # Get the index value from .Values.environments list
  # based on pass-in environment parameter
  {{ $myIndex = indexOf .Values.environments .Value.environment }}
  replicas: {{ .Values.perClusterValues.replicas $myIndex }}
  {{- end }}
</code></pre>
<p>I hope you understand my logic, but what is the correct syntax? Or is this even a good approach?</p>

Chris F
<p>You can use the <code>helm install -f</code> option to pass an extra YAML values file in, and this takes precedence over the chart's own <code>values.yaml</code> file.  So using exactly the template structure you already have, you can provide alternate values files</p>
<pre class="lang-yaml prettyprint-override"><code># sandbox.yaml
autoscaling:
  enabled: false
replicaCount: 1
</code></pre>
<pre class="lang-yaml prettyprint-override"><code># production.yaml
autoscaling:
  enabled: true
replicaCount: 5
</code></pre>
<p>And then when you go to deploy the chart, run it with</p>
<pre class="lang-sh prettyprint-override"><code>helm install myapp . -f production.yaml
</code></pre>
<p>(You can also <code>helm install --set replicaCount=3</code> to override specific values, but the <code>--set</code> syntax is finicky and unusual; using a separate YAML file per environment is probably easier.  Some tooling might be able to take advantage of JSON files also being valid YAML to write out additional deploy-time customizations.)</p>
