Inject ConfigMaps and Secrets · CKAD
Connect configuration at runtime instead of baking it into an image.
Learn with progress and quizzesFirst, understand the concepts.
Separate configuration types
ConfigMaps hold non-sensitive settings. Secrets help manage access to sensitive values, but base64 is encoding, not encryption; access control and at-rest protection still matter.
Reference mechanisms
Environment variables are read at startup; volumes expose files. Keys and mount paths must match what the application actually reads.
Minimize exposure
Do not print real tokens in logs or screenshots. This example checks whether a fake token file exists without displaying its contents.
Why it matters
Reuse images across environments and inject settings separately. Both ConfigMap and Secret references must match the keys and delivery method the application expects.
Work through the reasoning
Follow the reference
Trace env.valueFrom name and key to the object. It must be available in the Pod’s namespace. An object-name typo differs from a missing key.
Track sensitive values
Base64 representation is not encryption. Access permissions, encryption at rest, and log exposure are separate concerns. Use dummy lab values and verify presence without printing contents.
Learn by doing.
Use kubectl, a personal practice Kubernetes cluster, and a POSIX shell. Each lab uses its own namespace. Use example values only in Secrets. Cleanup removes the entire practice namespace.
Inject MODE through a ConfigMap environment variable and an example token as a Secret file. Use demo-only instead of real credentials.
kubectl config current-context
kubectl create namespace study-ckad-config --dry-run=client -o yaml | kubectl apply -f -
kubectl create configmap app-settings --from-literal=MODE=practice -n study-ckad-config --dry-run=client -o yaml | kubectl apply -f -
kubectl create secret generic app-token --from-literal=token=demo-only -n study-ckad-config --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -n study-ckad-config -f - <<'YAML'
apiVersion: v1
kind: Pod
metadata:
name: reader
spec:
containers:
- name: reader
image: busybox:1.36
command: ["sleep", "3600"]
env:
- name: MODE
valueFrom:
configMapKeyRef: {name: app-settings, key: MODE}
volumeMounts:
- {name: token, mountPath: /run/demo-secret, readOnly: true}
volumes:
- name: token
secret: {secretName: app-token}
YAML
kubectl wait --for=condition=Ready pod/reader -n study-ckad-config --timeout=120s
kubectl exec reader -n study-ckad-config -- printenv MODE
kubectl exec reader -n study-ckad-config -- sh -c 'test -s /run/demo-secret/token && echo secret-present'How to check your result
Look for practice and secret-present, without the Secret value itself. For FailedMount or CreateContainerConfigError, check reference names, keys, and namespaces first.
Clean up practice resources
Run after checking the result. Confirm these resources belong to your practice run and contain no data you need to keep.
kubectl delete namespace study-ckad-configApply what you learned
The ConfigMap exists, but the Pod reports CreateContainerConfigError. What else should you inspect?
Reveal the reasoning after trying
Compare namespace, reference name, and key, then read Events. The object may exist without the required key. You do not need to print Secret contents into shared logs to investigate references.
Ready to check your understanding?
Which statement about a Secret’s base64 representation is correct?
- It is strong encryption requiring no access control
- It is encoding and still needs access control
- No user can decode it
- It is always deleted when a container starts
Reveal the reasoning after trying
It is encoding and still needs access control
Base64 is an encoding. Permissions to read Secret objects and protection at rest must be managed separately.