Conditionally deploying a secret based on --set parameter

7/6/2019

I have a Helm chart that I am deploying to Azure Kubernetes Service, and minikube for development purposes.

When deploying to minikube, I need to add a secret so the cluster can speak with my Azure Container Registry. This is not necessary when I'm deploying to AKS.

Is there any way I can specify whether or not to include the secret through a --set value with helm install, or do I have to set up different helm charts?

-- djfinnoy
kubernetes-helm

1 Answer

7/6/2019

You can put anything you want inside a Go text/template conditional block, even whole Kubernetes resources.

# templates/some-secret.yaml
{{ if .Values.theSecret }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "some.name" . }}-some-secret
  labels:
    {{ template "some.labels" . | indent 4 }}
data:
  theSecret: {{ .Values.theSecret | b64enc }}
{{ end }}

Or, if you already have some shared Secret, you can make individual values conditional

data:
  someValue: {{ .Values.someValue | b64enc }}
{{- if .Values.theSecret }}
  theSecret: {{ .Values.theSecret | b64enc }}
{{- end }}

As the chart author you need to write this into the chart. If you're using a third-party chart, it's up to the chart author to provide this functionality.

-- David Maze
Source: StackOverflow