Search code examples
variableskuberneteskubernetes-secretskustomize

Kubernetes Cross secrets variables


I have a weird issue with envFrom:

 - name: template-api
 envFrom:
   - secretRef:
     name: common-secrets
   - secretRef:
     name: template-api

in common-secrets I have variables like this:

MAILHOST=smtp.gmail.com
MAILPORT=587

And template-api is like:

MAIL_HOST=$MAILHOST
MAIL_PORT=$MAILPORT

This is like that, because pods have different variables names for same info. But when the container is running the variables are replaced with literal $VAR instead of var value. Maybe Im using the wrong solution for this. Did somebody face the same issue?


Solution

  • Kubernetes won't update it that way, if you are running that approach with any code or script it will work inside the code. like process.env($MAILHOST)

    Whatever you have mentioned in secret it will get injected into the OS environment now if the same values are there it will get overwritten.

    Kubernetes inject the secret based on the YAML configuration either to the file system or either inside the OS.

    Kubernetes simply inject the values into the POD as set in secret. it won't check whether anything is already set in the environment and replaces it with values.