Bird
Raised Fist0
Kubernetesdevops~20 mins

Using ConfigMaps as environment variables in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ConfigMap Env Vars Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of Pod Environment Variables from ConfigMap
Given a ConfigMap named app-config with key-value pairs, and a Pod manifest that uses this ConfigMap as environment variables, what will be the output of printenv inside the Pod?
Kubernetes
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  LOG_LEVEL: DEBUG
  MAX_RETRIES: "5"
---
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: test-container
    image: busybox
    command: ["sh", "-c", "printenv"]
    envFrom:
    - configMapRef:
        name: app-config
ALOG_LEVEL=DEBUG\nMAX_RETRIES=5 (without quotes)\n... (other default env vars)
BLOG_LEVEL=DEBUG\nMAX_RETRIES=5\n... (other default env vars)
CNo environment variables from ConfigMap are set
DLOG_LEVEL=DEBUG\nMAX_RETRIES="5"\n... (other default env vars)
Attempts:
2 left
💡 Hint
Remember that ConfigMap values are strings and environment variables are strings without quotes.
❓ Configuration
intermediate
2:00remaining
Correct ConfigMap Reference in Pod Spec
Which of the following Pod specs correctly injects environment variables from a ConfigMap named my-config?
A
envFrom:
- configMapRef:
    name: my-config
B
env:
- name: my-config
  valueFrom:
    configMapKeyRef:
      name: my-config
      key: my-config
C
envFrom:
- secretRef:
    name: my-config
D
env:
- name: my-config
  value: my-config
Attempts:
2 left
💡 Hint
Check the correct field name for referencing ConfigMaps in envFrom.
❓ Troubleshoot
advanced
2:00remaining
Why Are ConfigMap Environment Variables Missing in Pod?
A Pod references a ConfigMap named settings using envFrom, but the environment variables are not available inside the container. What is the most likely cause?
AThe container image does not support environment variables
BThe Pod spec uses <code>envFrom: secretRef</code> instead of <code>configMapRef</code>
CThe ConfigMap <code>settings</code> does not exist in the same namespace as the Pod
DThe ConfigMap keys are empty strings
Attempts:
2 left
💡 Hint
ConfigMaps are namespace-scoped resources.
🔀 Workflow
advanced
3:00remaining
Order of Steps to Update ConfigMap Environment Variables in Running Pod
What is the correct order of steps to update environment variables from a ConfigMap in a running Pod?
A4,2,1,3
B4,1,2,3
C1,2,4,3
D1,4,2,3
Attempts:
2 left
💡 Hint
Remember to apply changes before deleting the Pod to pick up new config.
✅ Best Practice
expert
2:30remaining
Best Practice for Managing Sensitive Data with ConfigMaps as Environment Variables
Which approach is best practice when using ConfigMaps for environment variables that include sensitive data like passwords?
AStore sensitive data in Secrets and reference them separately from ConfigMaps
BStore sensitive data in ConfigMaps and use RBAC to restrict access
CEncode sensitive data in base64 and store in ConfigMaps
DStore sensitive data directly in Pod specs as environment variables
Attempts:
2 left
💡 Hint
Consider Kubernetes resource types designed for sensitive data.

Practice

(1/5)
1. What is the main purpose of using a ConfigMap in Kubernetes when setting environment variables for a pod?
easy
A. To separate configuration data from application code for easier updates
B. To store container images for pods
C. To manage network policies between pods
D. To define resource limits for containers

Solution

  1. Step 1: Understand ConfigMap role

    ConfigMaps hold configuration data separately from app code, allowing updates without rebuilding images.
  2. Step 2: Identify correct purpose

    Among options, only separating config data matches ConfigMap's main use for environment variables.
  3. Final Answer:

    To separate configuration data from application code for easier updates -> Option A
  4. Quick Check:

    ConfigMap purpose = separate config data [OK]
Hint: ConfigMaps separate config from code for flexible env vars [OK]
Common Mistakes:
  • Confusing ConfigMaps with container images
  • Thinking ConfigMaps manage network or resources
  • Using ConfigMaps to store secrets (use Secrets instead)
2. Which of the following is the correct syntax to load all keys from a ConfigMap named app-config as environment variables in a pod spec?
easy
A. envFrom: - configMapRef: name: app-config
B. env: - name: app-config valueFrom: configMapKeyRef: name: app-config
C. configMap: name: app-config
D. envFrom: - secretRef: name: app-config

Solution

  1. Step 1: Identify correct envFrom usage

    To load all keys as env vars, use envFrom with configMapRef and the ConfigMap name.
  2. Step 2: Check options for syntax correctness

    envFrom: - configMapRef: name: app-config correctly uses envFrom with configMapRef. Others misuse keys or use secretRef incorrectly.
  3. Final Answer:

    envFrom: - configMapRef: name: app-config -> Option A
  4. Quick Check:

    Use envFrom + configMapRef for all keys [OK]
Hint: Use envFrom with configMapRef to load all keys [OK]
Common Mistakes:
  • Using env instead of envFrom for all keys
  • Confusing configMapRef with secretRef
  • Missing indentation or wrong key names
3. Given this pod spec snippet, what environment variables will be available inside the container?
envFrom:
  - configMapRef:
      name: my-config
And the ConfigMap my-config contains keys: API_URL=https://api.example.com and TIMEOUT=30.
medium
A. Only API_URL=https://api.example.com
B. API_URL=https://api.example.com and TIMEOUT=30
C. Only TIMEOUT=30
D. No environment variables will be set

Solution

  1. Step 1: Understand envFrom with configMapRef

    Using envFrom with configMapRef loads all keys from the ConfigMap as environment variables.
  2. Step 2: Check ConfigMap keys

    The ConfigMap has two keys: API_URL and TIMEOUT, so both become env vars.
  3. Final Answer:

    API_URL=https://api.example.com and TIMEOUT=30 -> Option B
  4. Quick Check:

    envFrom loads all keys as env vars [OK]
Hint: envFrom loads all ConfigMap keys as env vars [OK]
Common Mistakes:
  • Assuming only one key loads at a time
  • Confusing envFrom with env and missing keys
  • Thinking ConfigMap keys are not environment variables
4. You applied this pod spec to use a ConfigMap as environment variables, but the container does not see the variables. What is wrong?
envFrom:
  - configMapRef:
      name: wrong-config-name
The ConfigMap you created is named app-config.
medium
A. The pod spec must use secretRef instead of configMapRef
B. envFrom cannot be used to load ConfigMaps
C. ConfigMaps cannot be used as environment variables
D. The ConfigMap name in the pod spec does not match the actual ConfigMap name

Solution

  1. Step 1: Compare ConfigMap names

    The pod spec references wrong-config-name, but the actual ConfigMap is app-config.
  2. Step 2: Understand impact of name mismatch

    If names don't match, Kubernetes cannot find the ConfigMap, so env vars won't be set.
  3. Final Answer:

    The ConfigMap name in the pod spec does not match the actual ConfigMap name -> Option D
  4. Quick Check:

    ConfigMap name must match exactly [OK]
Hint: Check ConfigMap name spelling matches pod spec [OK]
Common Mistakes:
  • Using secretRef instead of configMapRef incorrectly
  • Assuming envFrom can't load ConfigMaps
  • Ignoring case sensitivity in names
5. You want to update environment variables in a running pod without rebuilding the container image. Which approach using ConfigMaps is correct?
hard
A. Use a Secret instead of ConfigMap for environment variables
B. Modify the container image to include new environment variables
C. Create or update a ConfigMap and reference it with envFrom in the pod spec, then restart the pod
D. Edit the pod spec to add environment variables directly and redeploy the image

Solution

  1. Step 1: Understand ConfigMap update workflow

    ConfigMaps allow updating config data separately; updating the ConfigMap and restarting the pod applies new env vars without rebuilding images.
  2. Step 2: Evaluate options for best practice

    Create or update a ConfigMap and reference it with envFrom in the pod spec, then restart the pod correctly uses ConfigMap with envFrom and pod restart. Others require image rebuild or confuse Secrets with ConfigMaps.
  3. Final Answer:

    Create or update a ConfigMap and reference it with envFrom in the pod spec, then restart the pod -> Option C
  4. Quick Check:

    Update ConfigMap + restart pod for new env vars [OK]
Hint: Update ConfigMap and restart pod, no image rebuild needed [OK]
Common Mistakes:
  • Rebuilding container image unnecessarily
  • Confusing Secrets with ConfigMaps for non-sensitive data
  • Editing pod spec without restarting pod
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard