How to use a generated secret inside a yaml file generated by Helm?

4/20/2020

I have a service account token secret:

Version: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
  labels:
    app: {{ .Release.Name }}-{{ .Values.appName }}-secret
  name: {{ .Release.Name }}-api-secret
  annonations:
    kubernetes.io/service-account.name: ...

Once applied, a token will be generated and available under data.token.

How can I use data.token in another helm generated yaml?

-- znat
kubernetes-helm

1 Answer

4/20/2020

When you have the name (i.e. {{ .Release.Name }}-api-secret) of the secret, you can refer it from other k8s objects. Most of the time, these are local (same namespace) object references.

Use as env

env:
- name: TOKEN
  valueFrom:
    secretKeyRef:
      name: {{ .Release.Name }}-api-secret
      key: token

Mount in path

volumes:
- name: secret-volume
  secret:
    secretName: {{ .Release.Name }}-api-secret
containers:
- name: test-container
  image: demoImage
  volumeMounts:
  - name: secret-volume
    readOnly: true
    mountPath: "/etc/credentials"
-- Kamol Hasan
Source: StackOverflow