<p>I have different sets of <code>environment</code> variables per deployment/microservice and <code>vaule</code> for each environment (dev/test/qa) are different.</p>
<p>Do I need <code>overlay</code> file for each deployment/microservice against each environment (dev/test/qa) or I can managed with single overlay per environment?</p>
<p>Deployment - <code>app-1.yaml</code>:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-1
spec:
  template:
    spec:
      containers:
        - name: example-1
        image: example:1.0
        env:
          -Name: &quot;A1&quot;
          -Value: &quot;B1&quot;
        env:
          -Name: &quot;D1&quot;
          -Value: &quot;E1&quot;
</code></pre>
<p>Deployment - <code>app-2.yaml</code>:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-2
spec:
  template:
    spec:
      containers:
        - name: example-2
        image: example:2.0
        env:
          -Name: &quot;X1&quot;
          -Value: &quot;Y1&quot;
        env:
          -Name: &quot;P1&quot;
          -Value: &quot;Q1&quot;
</code></pre>

<p>You can use variable in the env value field as below.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-1
spec:
  template:
    spec:
      containers:
      - name: example-1
        image: example:1.0
        env:
        - Name: &quot;A1&quot;
          Value: ${A1_VALUE}
        - Name: &quot;D1&quot;
          Value: ${D1_VALUE}
</code></pre>
<p>Then, on <code>dev</code> env you can do the following.</p>
<pre><code>export A1_VALUE=&lt;your dev env value for A1&gt;
export D1_VALUE=&lt;your dev env value for D1&gt;

envsubst &lt; example-1.yaml | kubectl apply -f -
</code></pre>
<p>Then, on <code>qa</code> env you can do the following.</p>
<pre><code>export A1_VALUE=&lt;your qa env value for A1&gt;
export D1_VALUE=&lt;your qa env value for D1&gt;

envsubst &lt; example-1.yaml | kubectl apply -f -
</code></pre>
<p>You can also put those env variables in a file. For example, you  can have the following two env files.</p>
<p><code>dev.env</code> file</p>
<pre><code>A1_VALUE=a1_dev
D1_VALUE=b1_dev
</code></pre>
<p><code>qa.env</code> file</p>
<pre><code>A1_VALUE=a1_qa
D1_VALUE=b1_qa
</code></pre>
<p>Then, on <code>dev</code> environment, just run:</p>
<pre><code>❯ source dev.env
❯ envsubst &lt; example-1.yaml| kubectl apply -f -
</code></pre>
<p>On <code>qa</code> environment, just run:</p>
<pre><code>❯ source qa.env
❯ envsubst &lt; example-1.yaml| kubectl apply -f -
</code></pre>
<blockquote>
<p>Note that you have to install <code>envsubst</code> in your machine.</p>
</blockquote>
