Kubernetes set environment variables depending on namespace

7/20/2017

I want to set specific env variables depending on the namespace.

The goal is to have one config yaml file for different namespaces and set different env variables/config maps for dev, qa and prod depending on the namespace which the config file is applied to.

-- Tim Schwalbe
configuration
kubernetes
namespaces

1 Answer

7/20/2017

Afaik, kubernetes doesn't come with this capability out of the box.

There are two ways to get around this:

  1. Deploy a standard ConfigMap that contains everything any deployment needs. Make your app recognise the namespace and use the appropriate variable.
  2. Deploy a sidecar app that generates a namespace-specific ConfigMap from a template. This sidecar will need access to kube-apiserver to deploy new ConfigMap manifests automatically.
-- Eugene Chow
Source: StackOverflow