<p>I have 2 kubernetes descriptor files (yml): one for prod and one for test.
The only difference between them is the fact that in production I want up to 4 replicas to grant horizontal scaling, while in test I'm fine.
So the production yaml has the following more:</p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: prodAutoScaling
spec:
  maxReplicas: 4
 minReplicas: 1
 scaleTargetRef:
  apiVersion: extensions/v1beta1
kind: Deployment
name: myapp
 targetCPUUtilizationPercentage: 80
</code></pre>

<p>If it was possible to put this configuration inside a config map I could have two identical descriptors and avoid maintaining both.
Is this possible?</p>

Phate
<p>Check <a href="https://github.com/kubernetes-sigs/kustomize" rel="nofollow noreferrer">kustomize</a> it might be overkill just for one file, but later when a number of files increase it will be helpful.</p>

<ol>
<li>kustomize</li>
</ol>

<p><code>$ kubectl kustomize dev/</code></p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: dev-AutoScaling
spec:
  maxReplicas: 1
  minReplicas: 1
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: myapp
  targetCPUUtilizationPercentage: 80
</code></pre>

<p><code>$ kubectl kustomize prod/</code></p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: prod-AutoScaling
spec:
  maxReplicas: 4
  minReplicas: 1
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: myapp
  targetCPUUtilizationPercentage: 80
</code></pre>

<pre><code>.
├── base
│   ├── HorizontalPodAutoscaler.yaml
│   └── kustomization.yaml
├── dev
│   ├── kustomization.yaml
│   └── map.yaml
└── prod
    ├── kustomization.yaml
    └── map.yaml
</code></pre>

<p><code>$cat base/HorizontalPodAutoscaler.yaml</code></p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: AutoScaling
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: myapp
  targetCPUUtilizationPercentage: 80
  maxReplicas: 0
  minReplicas: 1
</code></pre>

<p><code>$cat base/kustomization.yaml</code></p>

<pre><code>resources:
- HorizontalPodAutoscaler.yaml
`$cat dev/kustomization.yaml`
bases:
- ../base
namePrefix: dev-
patchesStrategicMerge:
- map.yaml
</code></pre>

<p><code>$ cat dev/map.yaml</code></p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: AutoScaling
spec:
  maxReplicas: 1
</code></pre>

<p><code>$ cat prod/kustomization.yaml</code></p>

<pre><code>bases:
- ../base
namePrefix: prod-
patchesStrategicMerge:
- map.yaml
</code></pre>

<p><code>$ cat prod/map.yaml</code></p>

<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: AutoScaling
spec:
  maxReplicas: 4
</code></pre>

<ol start="2">
<li>ytt</li>
</ol>

<p>You can also use <a href="https://get-ytt.io/" rel="nofollow noreferrer">ytt</a> for templating.</p>
