A ConfigMap sits in the cluster. Three fields bring it into a container.
envFrom.configMapRefevery key becomes a variable
env[].valueFrom.configMapKeyRefone key, one variable, your name
volumes[].configMap + volumeMountsone file per key under a directory
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:
text
learner@shallows:~$ kubectl exec web -- printenv MARKET_NAME
monster-market-eu
learner@shallows:~$ kubectl exec web -- printenv REGION
eu-west-1
learner@shallows:~$ kubectl exec web -- ls /etc/market
MARKET_NAME
region
learner@shallows:~$ kubectl exec web -- cat /etc/market/region
eu-west-1envFrom from the command line
text
learner@shallows:~$ kubectl set env deploy/market-web --from=configmap/market-config
deployment.apps/market-web env updatedThe same as envFrom in the template, and it starts a rollout.
When values change
| Way in | After the ConfigMap changes |
|---|---|
Variables (envFrom, configMapKeyRef) | Unchanged until the Pod is recreated: kubectl rollout restart deploy/NAME |
| Files (volume) | Updated in place by the kubelet, within a minute |