How to set a different namespace for child helm charts?
Asked Answered
G

2

41

When you install a chart with a child chart that doesn't specify a namespace, Helm will use the one specified on command line via --namespace. Is it possible to override this flag for a specific child chart?

For example if I have chart A which depends on chart B and I specify --namespace foo, I want to be able to customize the resources of chart B to be installed into some other namespace bar instead of foo.

Geordie answered 27/6, 2018 at 23:45 Comment(0)
C
38

Update 2: Helm 3 added support for multi namespaces https://github.com/helm/helm/issues/2060 (however this does not enable implicit installation of a child chart into a different namespace from the parent chart without using the explicit namespace approach mentioned in Update 1 on all of the child chart's resources).

Update 1: If a resource template specifies a metadata.namespace, then it will be installed in that namespace. For example, if I have a pod with metadata.namespace: x and I run helm install mychart --namespace y, that pod will be installed in x. I guess you could use regular helm templates with the namespace to parameterize it.

Original answer:

We do not plan on fully supporting multi-namespaced releases until Helm 3.0 https://github.com/kubernetes/helm/issues/2060#issuecomment-306847365

As a workaround, you install for each namespace individually using --skip-dependencies or with dependency conditions

Ceballos answered 2/7, 2018 at 13:33 Comment(4)
Thanks for sharing Update 2. I am still unable to work out how helm 3 solve the problem of deploying child charts in a different namespace. Do you mind sharing an example?Oisin
I am not sure if helm 3 also solves this problem - at least it's not very clear if it solves the problem that the OP asked. Without specifying the metadata.namespace (which was supported earlier also), how do sub charts get installed into their own namespaces?Arkwright
One of the helm maintainers recommends helmfile to do this - github.com/helm/helm/issues/5358#issuecomment-628920908Arkwright
It's not the thing questioner wanted.Furculum
T
4

If you already have different charts then you can use helmfile to achieve this.

Step 1: create the following folder.

my-awesome-infrastructure/
  helm
  helmfile
  helmfile.yaml

Where helm and helmfile are the binary executables.

Step 2: install the helm diff plugin which is needed used helmfile.

helm plugin install https://github.com/databus23/helm-diff

Step 3: declare your charts in the helmfile.yaml.

helmBinary: ./helm

repositories:
  - name: ingress-nginx
    url: https://kubernetes.github.io/ingress-nginx
  - name: bitnami
    url: https://charts.bitnami.com/bitnami
releases:
  - name: nginx-ingress
    namespace: nginx-ingress
    createNamespace: true
    chart: ingress-nginx/ingress-nginx
    version: ~4.1.0
  - name: jupyterhub
    namespace: jupyterhub
    createNamespace: true
    chart: bitnami/jupyterhub
    version: ~1.1.12
  - name: metrics-server
    namespace: metrics-server
    createNamespace: true
    chart: bitnami/metrics-server
    version: ~5.11.9

Step 4: run helmfile to deploy all charts.

./helmfile apply

In the above example, you are deploying three separate charts to three separate namespaces. Under the covers, helmfile will run helm install separately and create separate releases.

Tipton answered 24/4, 2022 at 3:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.