henry.oswald
henry.oswald

Reputation: 5434

Insert all secrets as env variables into kubernetes deployment

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?

Upvotes: 13

Views: 5400

Answers (1)

Bal Chua
Bal Chua

Reputation: 1174

I used this for configmaps.

Same level as env which is .spec.containers:

envFrom:
   - secretRef:
       name: redis-secrets

Upvotes: 17

Related Questions