0

I have multiple apps based on the same chart deployed with Helm. Let's imagine you deploy your app multiple times with different configurations:

helm install myapp-01 mycharts/myapp
helm install myapp-02 mycharts/myapp
helm install myapp-03 mycharts/myapp

And after I update the chart files, I want to update all the releases, or maybe a certain range of releases. I managed to create a PoC script like this:

helm list -f myapp -o json | jq -r '.[].name' | while read i; do helm upgrade ${i} mycharts/myapp; done

While this works I will need to do a lot of things to have full functionality and error control. Is there any CLI tool or something I can use in a CI/CD environment to update a big number of releases (say hundreds of them)? I've been investigating Rancher and Autohelm, but I couldn't find such functionality.

jmservera
  • 6,454
  • 2
  • 32
  • 45
  • 1
    With plain `kubectl` and perhaps `kustomize` this is much easier to do. All you do to deploy is `kubectl apply` and you can pass a directory as argument. See e.g. https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/ – Jonas Sep 27 '21 at 18:11
  • Could this be achieved by having an overlay folder for each app? – jmservera Sep 27 '21 at 18:26
  • 1
    hundreds? You're well beyond needing a real deployment system. Have a look at argo, flux, jenkinsX, etc. – jordanm Sep 27 '21 at 18:30
  • @jmservera yes, that is one way to solve it. Then one command to deploy them all `kubectl apply -k` – Jonas Sep 27 '21 at 18:31
  • 1
    Thanks @Jonas, I could do it with kustomize and now it is easier to use and more flexible. I'll take a look later to argo and flux to see if I can enhance rollbacks as well with some other tools. Thanks for your help. – jmservera Oct 01 '21 at 13:55

1 Answers1

1

Thanks to the tip provided by @Jonas I've managed to create a simple structure to deploy and update lots of pods with the same image base.

I created a folder structure like this:

├── kustomization.yaml
├── base
│   ├── deployment.yaml
│   ├── kustomization.yaml
│   ├── namespace.yaml
│   └── service.yaml
└── overlays
    ├── one
    │   ├── deployment.yaml
    │   └── kustomization.yaml
    └── two
        ├── deployment.yaml
        └── kustomization.yaml

So the main trick here is to have a kustomization.yaml file in the main folder that points to every app:

resources:
- overlays/one
- overlays/two
namePrefix: winnp-

Then in the base/kustomization.yaml I point to the base files:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - service.yaml
  - deployment.yaml
  - namespace.yaml

And then in each app I use namespaces, sufixes and commonLabels for the deployments and services, and a patch to rename the base namespace:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: ns-one
nameSuffix: "-one"

commonLabels:
  app: vbserver-one

bases:
- ../../base

patchesStrategicMerge:

 - deployment.yaml

patches:
- target:
    version: v1 # apiVersion
    kind: Namespace
    name: base
  patch: |-
    - op: replace
      path: /metadata/name
      value: ns-one

Now, with a simple command I can deploy or modify all the apps:

kubectl apply -k .

So to update the image I only have to change the deployment.yaml file with the new image and run the command again.

I uploaded a full example of what I did in this GitHub repo

jmservera
  • 6,454
  • 2
  • 32
  • 45