<p>I have around 20 container app and for each one I have <code>deployment.yaml</code> and now let's say I want to put different <code>replicas</code> for each one. What below image suggest that I need to match <code>metadata:name</code>.</p>
<p>Is this means I need to create 20 <code>overlay.yaml</code> each for one container app? Can I managed all app with SINGLE overlay file?</p>
<p><a href="https://i.stack.imgur.com/AAB16.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AAB16.png" alt="enter image description here" /></a></p>

user584018
<p>This can be resolved by using <code>patches</code>. You will be able to manage all deployments with one overlay file per environment where you can set explicitly number of replicas for each deployment.</p>
<hr />
<p><strong>Here's a simplified example of it:</strong></p>
<p>I have two environments: <code>dev</code> and <code>stage</code>. Both have <code>kustomization.yaml</code> with <code>patches</code> for specific deploys and numbers of replicas (different for both envs).</p>
<p><code>tree command:</code></p>
<pre><code>.
├── base
│   ├── app-1.yaml
│   ├── app-2.yaml
│   └── kustomization.yaml
└── overlays
    ├── dev
    │   └── kustomization.yaml
    └── stage
        └── kustomization.yaml
</code></pre>
<p>Deployment - <code>app-1.yaml:</code> (2nd is almost identical, different name and image)</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-1
spec:
  template:
    spec:
      containers:
      - name: example-1
        image: example:1.0
</code></pre>
<p>Below a snippet from <code>overlays/dev/kustomization.yaml</code>:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../../base

patches:
  - patch: |-
      - op: replace
        path: /spec/replicas
        value: 2
    target:
      group: apps
      version: v1
      kind: Deployment
      name: example-1
  - patch: |-
      - op: replace
        path: /spec/replicas
        value: 3
    target:
      group: apps
      version: v1
      kind: Deployment
      name: example-2
</code></pre>
<p>Actual result:</p>
<pre><code>$ kubectl kustomize overlays/dev
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-1
spec:
  replicas: 2
  template:
    spec:
      containers:
      - image: example:1.0
        name: example-1
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-2
spec:
  replicas: 3
  template:
    spec:
      containers:
      - image: example:2.0
        name: example-2
</code></pre>
<hr />
<p><strong>Useful links:</strong></p>
<ul>
<li><a href="https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patches/" rel="nofollow noreferrer">Kustomize patches</a></li>
<li><a href="https://kubectl.docs.kubernetes.io/guides/config_management/components/" rel="nofollow noreferrer">Kustomize components</a> (this one is not directly connected, but idea is common)</li>
</ul>
