kubernetes - How to create a namespace if it doesn't exists from HELM templates?

ID : 131325

viewed : 10

Tags : kubernetesgoogle-cloud-platformnamespaceskubernetes-helmkubernetes

Top 5 Answer for kubernetes - How to create a namespace if it doesn't exists from HELM templates?

vote vote

96

This feature is implemented in helm >= 3.2 (Pull Request)

Use --create-namespace in addition to --namespace <namespace>

vote vote

80

For helm2 it's best to avoiding creating the namespace as part of your chart content if at all possible and letting helm manage it. helm install with the --namespace=<namespace_name> option should create a namespace for you automatically. You can reference that namespace in your chart with {{ .Release.Namespace }}. There's currently only one example of creating a namespace in the public helm/charts repo and it uses a manual flag for checking whether to create it

For helm3 functionality has changed and there's a github issue on this

vote vote

77

There are some differences in Helm commands due to different versions.

For Helm 2, just use --namespace; for Helm 3, need to use --namespace and --create-namespace.

Helm 2 Example:

helm install stable/nginx-ingress --name ingress-nginx --namespace ingress-nginx --wait 

Helm 3 Example:

helm install ingress-nginx stable/nginx-ingress --namespace ingress-nginx --create-namespace --wait 
vote vote

66

For terraform users, set create_namespace attribute to true:

resource "helm_release" "kube_prometheus_stack" {   name       = ...   repository = ...   chart      = ...   namespace  = ...   create_namespace = true } 
vote vote

52

Top 3 video Explaining kubernetes - How to create a namespace if it doesn't exists from HELM templates?

Related QUESTION?