<p>I'm working with a web app and there are multiple environments that we deploy this to; prod, staging, multiple QA environments, and even some developer environments when necessary. We're migrating to kubernetes from elastic beanstalk and trying to set up the config/yaml files in as clean a way as we can. The issue is, we've defined a yaml file for each environment that has some secrets in it, and this is getting a little bit hard to maintain with lots of copy/paste. Below is an example of the files/contents:</p>
<p><strong>disclaimer</strong> - this work was mostly done by the devops team and I'm a web engineer trying to assist them, so I will try to answer any questions as best as I can, but I may not have all the right answers</p>
<p>folder structure:</p>
<pre><code>- k8s // root folder
 - deployment.yaml
 - production
   - production-params.yaml
 - staging
   - staging-1-params.yaml
   - staging-2-params.yaml
   - qa-1-params.yaml
 - developers
   - some-dev-params.yaml
</code></pre>
<p>The contents of each one of these <code>*-params.yaml</code> files is almost identical, let's look at a couple examples.</p>
<p>production-params.yaml</p>
<pre><code>apiVersion: 'kubernetes-client.io/v1'
kind: ExternalSecret
metadata:
  name: prod-params
spec:
  backendType: systemManager
  data:
    - key:  /xxx/production/ENV_VAR_1
      name: ENV_VAR_1
    - key:  /xxx/production/ENV_VAR_2
      name: ENV_VAR_2
    - key:  /xxx/production/ENV_VAR_3
      name: ENV_VAR_3
    - key:  /xxx/production/ENV_VAR_4
      name: ENV_VAR_4
</code></pre>
<p>staging-1-params.yaml</p>
<pre><code>apiVersion: 'kubernetes-client.io/v1'
kind: ExternalSecret
metadata:
  name: prod-params
spec:
  backendType: systemManager
  data:
    - key:  /xxx/staging1/ENV_VAR_1
      name: ENV_VAR_1
    - key:  /xxx/staging1/ENV_VAR_2
      name: ENV_VAR_2
    - key:  /xxx/staging1/ENV_VAR_3
      name: ENV_VAR_3
    - key:  /xxx/staging1/ENV_VAR_4
      name: ENV_VAR_4
</code></pre>
<p>and every other params file is like this, with only the file paths in the 'key' changing, but its almost identical. Is there a way we can make these somewhat dynamic or cleaner? I'm not a devops/k8s pro and did some research, seems like Helm can be helpful here but not sure how to use it to solve this problem. I read a tutorial that was a little helpful but I'm still confused. If anyone knows of any resources or has solved this problem in the past, I'd really appreciate the help</p>

Abdul Ahmad
<p>This is the sort of replacement Helm is good at.  If you write a Helm chart, you can use its templating syntax to fill in a specific part of the YAML:</p>
<pre class="lang-yaml prettyprint-override"><code># templates/external-secret.yaml
apiVersion: 'kubernetes-client.io/v1'
kind: ExternalSecret
metadata:
  name: prod-params
spec:
  backendType: systemManager
  data:
    - key:  /xxx/{{ .Values.environment }}/ENV_VAR_1
      name: ENV_VAR_1
    - key:  /xxx/{{ .Values.environment }}/ENV_VAR_2
      name: ENV_VAR_2
{{/* etc. */}}
</code></pre>
<p>You can then provide a YAML file of settings per environment:</p>
<pre class="lang-yaml prettyprint-override"><code># production.yaml
environment: production
</code></pre>
<pre class="lang-yaml prettyprint-override"><code># staging-1.yaml
environment: staging-1
</code></pre>
<p>When you go to deploy the application, you can provide one of these files as a command-line option, and the contents of the file will be visible to the templating engine as <code>.Values</code>.</p>
<pre class="lang-sh prettyprint-override"><code>helm install the-app . -f staging-1.yaml
</code></pre>
<p>That approach would let you put all of the things that are &quot;the same&quot; in the <code>templates</code> directory, and all of the things that are different per environment in the per-environment YAML values files.</p>
