The same image runs in staging and production. What differs is the configuration it is given at start.
Three ways in
text
ConfigMap market-config
MARKET_NAME = monster-market-eu
region = eu-west-1
│
├── envFrom.configMapRef ──▶ every key becomes an env var
├── env[].valueFrom.configMapKeyRef ──▶ one key, one named var
└── volumes[].configMap + volumeMounts ──▶ one file per key under a pathCreate one
sh
kubectl create configmap market-config --from-literal=MARKET_NAME=monster-market-eu
kubectl create configmap market-config --from-file=region
kubectl get configmap market-config -o yaml--from-literal sets a key directly. --from-file uses the file name as the key and the file content as the value. Both can be repeated in one command.
A manifest holds the same data:
yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: market-config
data:
MARKET_NAME: monster-market-eu
region: eu-west-1Use it in a Pod
yaml
spec:
containers:
- name: web
image: stackmonsters/monster-market-web
envFrom:
- configMapRef:
name: market-config
env:
- name: REGION
valueFrom:
configMapKeyRef:
name: market-config
key: region
volumeMounts:
- name: cfg
mountPath: /etc/market
volumes:
- name: cfg
configMap:
name: market-configInside the container: printenv MARKET_NAME prints the value, REGION holds eu-west-1, and /etc/market/region is a file with the same content.
Next: build this for the Monster Market and read the values back from inside the Pod.