KCNA Kubernetes Fundamentals Practice Question
A developer wants to inject environment variables into a pod from a ConfigMap named 'app-config'. Which YAML snippet correctly mounts all key-value pairs from the ConfigMap as environment variables?
⚠ Common exam trap
Watch out — candidates often confuse `envFrom` (bulk injection) with `env` + `configMapKeyRef` (single key injection) or volume mounts (file-based injection), leading them to pick options that inject only one key or mount files instead of environment variables.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
envFrom: - configMapRef: name: app-config
`envFrom` with a `configMapRef` injects all key-value pairs from the ConfigMap named 'app-config' as environment variables into the container. This is the standard Kubernetes method for bulk injection of ConfigMap data into environment variables, as opposed to selecting individual keys.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
env: - name: CONFIG value: "$(CONFIGMAP)"
Why it's wrong here
This sets a literal string value, not a ConfigMap reference; $(CONFIGMAP) is variable expansion syntax, not a configMapKeyRef, so no keys are injected. It is tempting because env with name/value is the correct structure for environment variables, and would work if the value were a genuine reference or literal.
- ✓
envFrom: - configMapRef: name: app-config
Why this is correct
Using `envFrom` with `configMapRef` imports every key-value pair from `app-config` as environment variables in one declaration, satisfying the requirement to mount all pairs rather than selecting individual keys. The alternative `valueFrom.configMapKeyRef` maps a single key per variable, so it cannot expose the whole ConfigMap without listing each key explicitly.
- ✗
volumes: - name: config configMap: name: app-config volumeMounts: - name: config mountPath: /etc/config
Why it's wrong here
Volumes mount ConfigMap keys as files under a path, not as environment variables, so the container reads /etc/config files rather than env vars. It is tempting because volume mounts are the standard way to consume ConfigMaps as configuration files, and would be correct if the requirement were file-based config rather than environment injection.
- ✗
env: - name: CONFIG valueFrom: configMapKeyRef: name: app-config key: config.yaml
Why it's wrong here
configMapKeyRef with a key injects one specific value, so only the config.yaml entry becomes CONFIG rather than every key-value pair. It is tempting because it targets a named ConfigMap, and would be correct when a single key must be exposed as one environment variable.
Go deeper
Related to this question
About these practice questions
This KCNA question is part of Courseiva's 930-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
2 more ways this is tested on KCNA
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A DevOps engineer has created a ConfigMap named 'app-config' and wants to use it to set environment variables in a pod. Which field in the pod spec should reference the ConfigMap?
medium- A.spec.containers[].command
- B.spec.containers[].env.name
- C.spec.containers[].volumeMounts
- ✓ D.spec.containers[].envFrom
Why D: `spec.containers[].envFrom` allows you to inject all key-value pairs from a ConfigMap (or Secret) as environment variables into a container in a single declaration. This field supports a `configMapRef` that references the ConfigMap by name, making it the appropriate spec field for bulk environment variable injection.
Variation 2. A DevOps engineer has created a ConfigMap named 'app-config' with some configuration data. They want to make that data available as environment variables in a pod. Which field in the pod spec should they use to achieve this?
medium- A.spec.volumes
- B.spec.containers[].volumeMounts
- ✓ C.spec.containers[].envFrom
- D.spec.containers[].env
Why C: The `envFrom` field in the container spec allows you to inject all key-value pairs from a ConfigMap (or Secret) as environment variables into the container. This is the most direct and efficient way to expose ConfigMap data as environment variables without needing to specify each key individually.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This KCNA practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the KCNA exam.