Summary - ConfigMap
- Docker & Kubernetes course
- Intermediate
- Lesson 48/82
- 5 min
Combine YAML and volume mount to write a configurable Pod.
Summary: ConfigMap
In this group:
- A ConfigMap separates non-secret settings from the image;
datavalues are strings. - Creation:
--from-literal,--from-file,--from-env-fileor YAML. - Environment variables:
envFrom.configMapRef(all) orconfigMapKeyRef(one); the pod is restarted for changes. - Volume: each key becomes a file; updates show up by themselves (except with
subPath). - Updating:
--dry-run=client -o yaml | kubectl apply -f -androllout restart.
kubectl create cm api-ayar --from-env-file=api.env
kubectl rollout restart deploy/apiPractice Config from an env file
Write three commands: create the api-ayar ConfigMap from the api.env file with --from-env-file; show it in detail; restart the api deployment.
Starter code
# buraya yazSample solution
kubectl create configmap api-ayar --from-env-file=api.env
kubectl describe configmap api-ayar
kubectl rollout restart deployment/apiExpected output
configmap/api-ayar created Name: api-ayar Data ==== DB_HOST: ---- db LOG_LEVEL: ---- info deployment.apps/api restarted
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which method is chosen so a config change reaches the application without restarting the pod?
- configMapKeyRef
- Baking it into the image
- Mounting as a volume (without subPath) and the app rereading the file Correct answer
- envFrom
Explanation: Environment variables are only read when the process starts.
2 List the ConfigMaps.
kubectl get ____
kubectl get cm
Explanation: cm is short for configmaps.
3 Match.
| Term | Meaning |
|---|---|
envFrom |
Environment variable |
volume |
File |
rollout restart |
Make it read the new value |
Secret |
For secret data |