0

I have around 20 container app and for each one I have deployment.yaml and now let's say I want to put different replicas for each one. What below image suggest that I need to match metadata:name.

Is this means I need to create 20 overlay.yaml each for one container app? Can I managed all app with SINGLE overlay file?

enter image description here

user584018
  • 10,186
  • 15
  • 74
  • 160
  • 1
    Yes, you need 20 overlays, if each should have unique config. – Jonas Jul 02 '21 at 15:38
  • Yes. I have different configuration for each service like custom environment variables as well. – user584018 Jul 02 '21 at 15:40
  • If I have 4 deployment environment then I will have 4*20 = 80 overlays. That's huge maintenance. Don't we have any centralize way with minimum overlay files? – user584018 Jul 02 '21 at 15:41
  • 1
    Is replicas different for all 4 environments? If you can set a default that covers 3 then you only need 20 overlays. – jordanm Jul 02 '21 at 21:02

1 Answers1

2

This can be resolved by using patches. 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.


Here's a simplified example of it:

I have two environments: dev and stage. Both have kustomization.yaml with patches for specific deploys and numbers of replicas (different for both envs).

tree command:

.
├── base
│   ├── app-1.yaml
│   ├── app-2.yaml
│   └── kustomization.yaml
└── overlays
    ├── dev
    │   └── kustomization.yaml
    └── stage
        └── kustomization.yaml

Deployment - app-1.yaml: (2nd is almost identical, different name and image)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-1
spec:
  template:
    spec:
      containers:
      - name: example-1
        image: example:1.0

Below a snippet from overlays/dev/kustomization.yaml:

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

Actual result:

$ 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

Useful links:

moonkotte
  • 3,661
  • 2
  • 10
  • 25
  • 1
    you're genius. Thanks for your reply. I have one interesting case, per microservice I have different sets of environment variable. Will `Path` helps here? – user584018 Jul 08 '21 at 03:21
  • Here I asked another question, https://stackoverflow.com/questions/68295287/can-i-managed-using-single-overlay-per-environment-dev-test-qa-where-environme – user584018 Jul 08 '21 at 03:34