Question 272 of 302
CKA Workloads and Scheduling Practice Question
Which TWO of the following are valid ways to expose environment variables from a ConfigMap to a pod? (Select TWO.)
⚠ Common exam trap
Watch out — candidates often confuse `envFrom` with `configMapRef` (which injects all keys) with the `env` field using `valueFrom` and `configMapKeyRef` (which injects a single key), and they may also mistakenly think mounting a ConfigMap as a volume sets environment variables, when it actually creates files.
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
✓
Using envFrom with configMapRef
`envFrom` with `configMapRef` allows you to inject all key-value pairs from a ConfigMap as environment variables into a pod, which is a concise way to expose ConfigMap data without specifying each key individually. This is a native Kubernetes feature that automatically creates environment variables for each entry in the ConfigMap.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Using envFrom with secretRef
Why it's wrong here
Using envFrom with secretRef is invalid for exposing ConfigMap data because secretRef refers to a Secret object, not a ConfigMap. While envFrom can accept both configMapRef and secretRef as separate source types, this option would inject Secret entries (e.g., base64-decoded values) rather than the key-value pairs from the ConfigMap. Since the question specifically asks about exposing environment variables from a ConfigMap, secretRef is the wrong source reference.
- ✗
Using env field with configMapKeyRef directly
Why it's wrong here
The env field in a container spec cannot hold configMapKeyRef directly as a child entry; it must be nested under a valueFrom field. A direct configMapKeyRef under env would produce a schema validation error because the expected structure is env: - name: VARIABLE valueFrom: configMapKeyRef: name: config-map-key-ref. Without valueFrom, the key reference has no defined mechanism to populate an environment variable.
- ✓
Using envFrom with configMapRef
Why this is correct
Using envFrom with configMapRef is a valid and straightforward way to expose all key-value pairs from a ConfigMap as environment variables. The configMapRef field inside envFrom specifies a source ConfigMap by name, and Kubernetes populates every entry from that ConfigMap into the container's environment. This is ideal when you want to inject multiple variables without listing each key individually, though you may still override specific keys using the env field.
- ✗
Mounting the ConfigMap as a volume, which automatically sets environment variables
Why it's wrong here
Mounting a ConfigMap as a volume creates files in the container's filesystem at the specified mount path, with each key represented as a file name and its value as the file content. This does not automatically set environment variables; the files are only accessible via disk reads unless you explicitly read them in your application or init script. Therefore, this method is not a valid way to expose ConfigMap data as environment variables directly.
- ✓
Using env field with valueFrom and configMapKeyRef
Why this is correct
The env field with valueFrom and configMapKeyRef is a valid way to expose a specific key from a ConfigMap as an environment variable. The valueFrom wrapper indicates that the variable's value should be sourced from an external reference, and configMapKeyRef specifies the ConfigMap name and the key to extract. This allows you to cherry-pick individual entries and optionally give the environment variable a different name than the ConfigMap key.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 24, 2026
This CKA 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 CKA exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.