CodeBlanks Logo Icon CodeBlanks

Summary - ConfigMap

Combine YAML and volume mount to write a configurable Pod.

Summary: ConfigMap

In this group:

  • A ConfigMap separates non-secret settings from the image; data values are strings.
  • Creation: --from-literal, --from-file, --from-env-file or YAML.
  • Environment variables: envFrom.configMapRef (all) or configMapKeyRef (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 - and rollout restart.
kubectl create cm api-ayar --from-env-file=api.env
kubectl rollout restart deploy/api

Practice 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

terminal
# buraya yaz

Sample solution

terminal
kubectl create configmap api-ayar --from-env-file=api.env
kubectl describe configmap api-ayar
kubectl rollout restart deployment/api

Expected 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.

Question
kubectl get ____
Answer
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

All lessons in Intermediate