Environment variables typed into a spec work for one Pod. Three Deployments that share a setting should share one object.
A ConfigMap
A ConfigMap is key and value pairs, stored in the cluster as an object of its own:
yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: market-config
data:
MARKET_NAME: monster-market-eu
region: eu-west-1It has no spec; it has data. It is namespaced, like a Pod. cm is its short name.
Create one
text
learner@shallows:~$ kubectl create configmap market-config --from-literal=MARKET_NAME=monster-market-eu --from-literal=region=eu-west-1
configmap/market-config created| Flag | Key | Value |
|---|---|---|
--from-literal=K=V | K | V |
--from-file=settings.conf | settings.conf | The whole file |
--from-file=region=/path/to/file | region | The whole file |
Both flags may be repeated and mixed in one command.
Read it
text
learner@shallows:~$ kubectl get configmap market-config -o yaml
apiVersion: v1
data:
MARKET_NAME: monster-market-eu
region: eu-west-1
kind: ConfigMapkubectl describe cm market-config prints the same data as a report.
Why
imagethe same everywhere
plus
ConfigMapdiffers per cluster, namespace, team
The image is built once and never changes. What changes between staging and production is the ConfigMap next to it. The next lesson connects the two.