Checking the Running Pod
First, check how many pods are currently running. In this example, we’re working with a single pod named “webapp-color”:APP_COLOR variable, which in this case is set to pink:
Updating the Pod to Change the Environment Variable
To change the background color of the web application, update theAPP_COLOR environment variable. Start by editing the pod manifest using:
Pods are immutable, so while you can edit a pod’s manifest, the changes cannot be applied directly. Instead, save the modified manifest locally and force replace the pod.
APP_COLOR value is updated to "green":
/tmp/kubectl-edit-3135302771.yaml). Force replace the existing pod with the updated manifest:
APP_COLOR is set to green, and the web application’s background should display green.
Working with ConfigMaps
In addition to direct environment variable updates, Kubernetes supports managing configurations with ConfigMaps. This provides a dynamic way to update environment variables for your pods.Listing Existing ConfigMaps
To see the current ConfigMaps in the default namespace, run:Inspecting a Specific ConfigMap
To check the database host specified in thedb-config ConfigMap, describe it:
DB_HOST is set to SQL01.example.com.
Creating a New ConfigMap for the Web Application
For the web application pod, we want to use a ConfigMap to set the environment variable dynamically. Create a new ConfigMap that setsAPP_COLOR to dark blue:
webapp-config-map containing the desired environment variable.
Updating the Pod to Use the New ConfigMap
Next, update the pod manifest so that the web application retrieves its environment variables from the ConfigMap instead of a static declaration. Modify the manifest to remove the directenv key and add an envFrom reference:
APP_COLOR environment variable from the webapp-config-map ConfigMap. When you access the web application, the background color will have changed to dark blue.
In this lab, you learned how to update environment variables both directly in a pod manifest and dynamically using ConfigMaps. These skills are essential for managing application configurations in Kubernetes.