Skip to main content
In this lab we will inspect Pod environment variables, update a Pod to change the app color, create and consume a ConfigMap, and replace an immutable Pod spec by recreating the Pod from an edited manifest.

Pod inspection and environment variables

  1. Check how many pods exist in the cluster:
For this exercise there is a single pod named webapp-color.
  1. Inspect the Pod to view container details and environment variables:
Relevant portion of the describe output:
From this output:
  • Environment variable name: APP_COLOR
  • Current value: pink
Open the web application UI (the cluster usually provides a link) and confirm the page background is pink.

Change the Pod color to green

Goal: update the environment variable so the web app displays a green background. Important: Many Pod spec fields are immutable. Attempting to edit and save certain fields for a running Pod will produce an error. Example error when trying to update immutable fields:
Direct edits to immutable Pod fields will be rejected. Use kubectl edit to create a local copy of your changes (kubectl saves the attempted edit to a temp file), then replace the Pod by deleting and recreating it from that edited manifest.
Recommended workflow:
  1. Run kubectl edit pod webapp-color and change the env value for APP_COLOR from pink to green. When you save, the API will reject the edit, but kubectl keeps your changed manifest in a temporary file (for example: /tmp/kubectl-edit-3135302771.yaml).
  2. Replace the Pod using the saved file:
Example output:
  1. After the Pod is recreated and Ready, open the web UI again and verify the background color is now green.
Pod specs have many immutable fields. If you need to change an immutable field for a Pod, recreate it with the updated manifest or use higher-level controllers (for example, a Deployment) which support rolling updates.

ConfigMaps: list and inspect

  1. List ConfigMaps in the default namespace:
Sample output:
In this example there are two ConfigMaps in the default namespace.
  1. Inspect the db-config ConfigMap to find the database host:
Relevant output:
From this ConfigMap, the database host is SQL01.example.com.

Create a ConfigMap for the webapp

Create a ConfigMap that provides APP_COLOR='dark blue' for the webapp:
Verify the ConfigMap:
You should see APP_COLOR: "dark blue" under data:.

Update the Pod to consume the ConfigMap

There are two common ways to expose ConfigMap data to a container as environment variables:
  • Set individual env vars using valueFrom.configMapKeyRef for specific keys.
  • Import all keys from a ConfigMap using envFrom with configMapRef.
We will use envFrom to import every key from webapp-config-map. Because the Pod spec is immutable for many fields, follow the same replace workflow:
  1. Run kubectl edit pod webapp-color and modify the container spec to include envFrom. The container section should resemble:
  1. Save the edit (kubectl typically stores it at a path like /tmp/kubectl-edit-1925296777.yaml) and then force-replace the Pod:
You will see:
  1. Verify the Pod now consumes the ConfigMap:
Look for the Environment Variables source information:
Open the web app again — the background should now be dark blue as supplied by the webapp-config-map.

Quick reference: common ConfigMap-to-env methods

Additional examples and references

Example Pod snippet using valueFrom.configMapKeyRef:
Example Pod snippet using envFrom to import all keys:

Summary

  • We inspected a Pod’s environment variables and identified APP_COLOR.
  • We attempted to change the Pod env var (immutable fields prevent direct updates), used kubectl edit to create a local manifest, then replaced the Pod with kubectl replace --force.
  • We created a ConfigMap (webapp-config-map) and updated the Pod to import that ConfigMap using envFrom.
  • Finally, we verified the application picked up the new color provided by the ConfigMap.

Watch Video