Courseiva
Workloads and SchedulingmediumMultiple ChoiceObjective-mapped

CKA Workloads and Scheduling Practice Question

You create a ConfigMap named 'app-config' with key 'database.url'. Which command correctly creates a pod that injects this ConfigMap value as an environment variable named 'DB_URL'?

⚠ Common exam trap

Many candidates assume `kubectl run` with a simple flag can directly map a ConfigMap key to a custom environment variable name, but Kubernetes does not provide a single-command shortcut for this; you must use a YAML manifest with `configMapKeyRef`.

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

Create a pod YAML with env.valueFrom.configMapKeyRef

To inject a specific key from a ConfigMap as a pod environment variable with a custom name, you must use a pod YAML with `env.valueFrom.configMapKeyRef`. This allows you to reference the ConfigMap key `database.url` and map it to the environment variable `DB_URL`. The `kubectl run` command does not support directly mapping a ConfigMap key to a custom environment variable name in a single command.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • kubectl run my-pod --image=nginx --envFrom=configmap/app-config

    Why it's wrong here

    This option is incorrect because the `kubectl run` command does not support a `--envFrom` flag. While `envFrom` is a valid field in a Pod specification, allowing all key-value pairs from a ConfigMap to be injected as environment variables, `kubectl run` is a high-level command designed for quick deployments and does not expose the full Pod API via command-line flags for complex configurations like `envFrom`. To use `envFrom`, a declarative Pod YAML definition is required.

  • Create a pod YAML with env.valueFrom.configMapKeyRef

    Why this is correct

    This is the correct and Kubernetes-native method for injecting a specific key's value from a ConfigMap into a container's environment. By defining the `env` variable within the Pod's YAML specification and utilizing `valueFrom.configMapKeyRef`, you explicitly reference the ConfigMap's name and the desired key. This declarative approach ensures precise control over environment variable injection and is the standard practice for managing application configurations.

  • kubectl run my-pod --image=nginx --env="DB_URL=configmap:app-config:database.url"

    Why it's wrong here

    This option is incorrect because the syntax `configmap:app-config:database.url` is not a valid way to reference a ConfigMap key using the `kubectl run --env` flag. The `--env` flag expects simple `KEY=VALUE` pairs or specific Kubernetes object references using `fieldRef` or `resourceFieldRef` syntax, but it does not support this custom colon-separated format for ConfigMap key extraction. Attempting to use this non-standard syntax will result in an invalid command execution.

  • kubectl run my-pod --image=nginx --from-configmap=app-config

    Why it's wrong here

    This option is incorrect because `--from-configmap` is not a valid flag for the `kubectl run` command. While `kubectl create configmap` uses flags like `--from-file` or `--from-literal` to define a ConfigMap's content, `kubectl run` does not provide a corresponding flag to directly consume an existing ConfigMap and inject its contents as environment variables into a new pod. This flag simply does not exist in the `kubectl run` command's API.

About these practice questions

Courseiva writes every CKA question from scratch — 302 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.