Skip to main content
In this lab you will inspect a running Pod’s environment, modify an environment variable, and then switch the Pod to consume its configuration from a ConfigMap. This walkthrough covers the common kubectl patterns used when pod fields are immutable and demonstrates how to use envFrom to import all keys from a ConfigMap.

1) Inspect the existing Pod and its environment variable

List pods in the current namespace:
Example output:
Describe the Pod to inspect the container spec and environment variables:
Relevant excerpt (cleaned for readability):
  • The environment variable APP_COLOR is set to pink.
  • Visiting the web application confirms the UI background is pink.

2) Update the Pod environment variable directly (immutable fields limitation)

Most Pod fields are immutable. Changing certain fields (including container environment values) via an in-place patch is not allowed by the API. The usual workflow is to fetch the Pod manifest, edit the desired fields locally, and then replace the Pod by deleting and recreating it from the edited manifest. Fetch and edit the Pod manifest with kubectl:
If you try to change spec.containers[*].env[*].value in-place, the API will reject the update with an error like:
kubectl writes your edits to a temporary file (for example /tmp/kubectl-edit-XXXX.yaml). In that file, change the APP_COLOR value to green. Then replace the Pod by forcing a delete and recreate:
Example output:
Verify the Pod restarted and the UI now shows the new color (green).
Pods are immutable for many fields. Using kubectl replace --force -f <file> deletes and recreates the pod from the provided manifest—this is a common technique to apply changes that cannot be done in-place.

3) Inspect ConfigMaps to find DB_HOST

List ConfigMaps in the default namespace:
Example output:
Describe the db-config ConfigMap to inspect its data:
Relevant output:
  • The database host is SQL01.example.com (case-insensitive for answers).

4) Create a ConfigMap to provide APP_COLOR for the Pod

Create a ConfigMap named webapp-config-map with the key APP_COLOR and value dark blue:
Verify the ConfigMap contents:
Expected snippet:

5) Update the Pod to consume environment variables from the ConfigMap

Rather than setting each environment variable individually, you can import all keys from a ConfigMap using envFrom with configMapRef. Update the container spec to include:
Because Pod specs are immutable for many fields, open the Pod manifest for editing:
Add the envFrom block under the container spec, save the temporary file created by kubectl (e.g. /tmp/kubectl-edit-YYYY.yaml), and then replace the Pod:
Example output:
Describe the recreated Pod to confirm it references the ConfigMap:
Relevant output:
  • The Pod now loads APP_COLOR from the webapp-config-map ConfigMap and the UI should display dark blue.

Quick reference — commands used in this lab

Summary

  • You inspected the Pod and found APP_COLOR=pink.
  • Direct in-place edits to change certain Pod fields are blocked by immutability rules; editing and then using kubectl replace --force -f <file> is the recommended approach to apply such changes.
  • You retrieved DB_HOST from the db-config ConfigMap (SQL01.example.com).
  • You created a ConfigMap webapp-config-map with APP_COLOR="dark blue".
  • You updated the Pod to import environment variables from the ConfigMap using envFrom: - configMapRef: name: webapp-config-map, then recreated the Pod so it picks up dark blue.

Watch Video