Insert all secrets as env variables into kubernetes deployment

10/4/2018

I have dozens of secrets to pass into a k8 deployment which becomes very verbose, bellow is an example of passing the redis secrets in from the redis-secrets secret.

- name: REDIS_HOST
  valueFrom:
    secretKeyRef:
      name: redis-secrets
      key: REDIS_HOST
- name: REDIS_PASSWORD
  valueFrom:
    secretKeyRef:
      name: redis-secrets
      key: REDIS_PASSWORD
- name: REDIS_PORT
  valueFrom:
    secretKeyRef:
      name: redis-secrets
      key: REDIS_PORT

Is it possible to pass all the secrets from redis-secrets into the deployment, with the keys of the secrets being the env variable key?

-- henry.oswald
google-kubernetes-engine
kubernetes
kubernetes-secrets

1 Answer

10/4/2018

I haven't tried this on secrets but its worth a try. I used this in configmaps.

Same level as env which is .spec.containers

envFrom: - secretRef: name: redis-secrets

-- Bal Chua
Source: StackOverflow