Dynamic namespace variable in helm chart

3/27/2019

I work with four teams that are using exactly the same environments that are set up in kubernetes namespaces. I have created helm charts to install those environments. Everything works fine but I have to create ingresses by hand because of the following format in hostname:

<namespace>.<app>.<k8sdomain>

The thing is I would like to just change context with kubectl and then run those charts instead of editing every single values.yaml to change namespace variable.

Is it possible to use some predefined or dynamic variable that would add the correct namespace to the host in ingress?

Or is there any other solution that would help me to solve this problem?

Thanks.

-- Thomas
kubernetes
kubernetes-helm

1 Answer

3/27/2019

The namespace value can be derived either from --namespace parameter which is the same namespace where helm chart is deployed to. In the charts it should be accessed with {{.Release.Namespace}} then. Or you can set these namespaces using --set when deploying helm chart with helm upgrade. If there are few environments you can access them as aliases in values.yaml and then set namespaces values for them like this:

helm upgrade \
   <chart_name> \
      <path_to_the_chart> \
        --set <environment_one>.namespace=namespace1 \
        --set <environment_two>.namespace=namespace2 \
...
-- Anna Slastnikova
Source: StackOverflow