Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 689
henry.oswald Avatar asked Feb 04 '23 21:02

henry.oswald


1 Answers

I used this for configmaps.

Same level as env which is .spec.containers:

envFrom:
   - secretRef:
       name: redis-secrets
like image 86
Bal Chua Avatar answered Feb 11 '23 22:02

Bal Chua