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

本秂侑毒 提交于 2020-04-10 07:42:27

问题


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 kubernets cluster


回答1:


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




回答2:


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

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



来源:https://stackoverflow.com/questions/51783651/how-to-create-a-namespace-if-it-doesnt-exists-from-helm-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!