Whats the best way for stage-specific K8s config? Whats the best way for stage-specific K8s config? kubernetes kubernetes

Whats the best way for stage-specific K8s config?


I would handle general configuration via ConfigMaps. Create configuration for each environment and have your pods/deployment consume the values via environment variables.

This approach allows you to decouple your configuration from your k8 object definition and gives the ability to inject the required config per environment.

For sensitive data, which might include a username and password in a connection string for example, consider using Secrets instead.


The best way in my experience is to use a higher level construct like Helm Chart. This way you manage all your manifests in platform agnostic way and make them configurable during chart install/update.

That way you can use both ConfigMaps, Secrets or env vars, and populate them from values set during install/upgrade. With helm, you would do it somewhat like this :

  • helm install -f values.yaml : where values yaml contains all your non-default values (ie. db password)
  • helm upgrade <release> --reuse-values --set image.tag=1.0.1 to say release a new version keeping all other values defined during initial install.

For non-default components like ie. development database, you can use value like devdb.enabled with a default value to false and set it to true only on dev env where you want to launch devdb pod and point your database service there (all the logic for it within manifest templates in helm chart)