ITChap
ITChap

Reputation: 4732

Set the same environment variables on all containers of the same pod

I would like the set the same env variable to the same value on all the containers of my pod. I am not trying to pass info between containers so this variable will not be updated but I want to ensure that if somebody update its value, it will be kept in sync across all the containers in my pod.

Is there any way to do this out of the box? Currently I see two options:

But Pods being a "single unit" it seems odd that there wouldn't be a way to define "pod-wide" env variables.

Upvotes: 3

Views: 3627

Answers (1)

PjoterS
PjoterS

Reputation: 14084

There are a few ways.

  1. The most common practice is as you mention using ConfigMap. This way is explain in Kubernetes docs.

  2. Another option is to use Secret, however it's similar to ConfigMap way.

  3. If you know that variable before deploying, you can Define an environment variable for a container

  4. Last method is to set them manually in each container, however it's harsh way.

There is also a good comparsion of passing environmental variable in medium article.

Upvotes: 3

Related Questions