Home > Back-end >  How can I share some value between kubernetes pods?
How can I share some value between kubernetes pods?

Time:11-30

I have several pods which belong to the same service. I need to share a value between all pods in this service.

Per my understanding, the shared volume won't work well, because pods may end up being on different nodes.

Having any kind of database (even most lightweight) exposed as a service to share this value would be overkill (however, probably it's my backup plan).

I was wondering whether there is some k8s native way to share the value.

CodePudding user response:

Put the values in a ConfigMap and mount it in the Pods. You can include the values of the ConfigMap in the containers of a Pod either as a volume or as environment variables.

See Configure a Pod to Use a ConfigMap in the Kubernetes documentation.

If the Pods need to update the shared values they can write to the ConfigMap (requires Kubernetes API permissions). However, in this case the ConfigMap must be included as a volume, since environment variable values from a ConfigMap are not updated when the ConfigMap changes.

  • Related