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

Kasun Siyambalapitiya picture Kasun Siyambalapitiya · Aug 10, 2018 · Viewed 15.5k times · Source

I have a kind: Namespace template yaml like follows,

apiVersion: v1
kind: Namespace
metadata:
  name: {{ .Values.namespace }}
  namespace: ""

How do I make helm install create the above-given namespace ({{ .Values.namespace }}) if and only if above namespace ({{ .Values.namespace }}) doesn't exits in the pointed Kubernetes cluster

Answer

Mathieu picture Mathieu · Mar 23, 2020

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

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