Skip to main content
Hi, I’m Sanjeev, one of the co-instructors for this course. In this lesson, we will walk through the solution for the ConfigMap section of the assignment in a step-by-step manner. ─────────────────────────────

1. Determining the Number of Pods

Begin by checking how many pods are currently running in your system. Execute the following command:
This confirms that there is one active pod, named webapp-color. ─────────────────────────────

2. Identifying the Environment Variable in the Pod

Next, determine which environment variable is configured in the container by describing the pod:
Search for the Environment section in the output. An example excerpt might look like:
From the Environment section, note that the variable APP_COLOR is set (ensure you select the correct one if multiple similar names are present). ─────────────────────────────

3. Verifying the Environment Variable Value

Verify the value of the APP_COLOR variable. The output above indicates that its value is pink. ─────────────────────────────

4. Viewing the Web Application

Click on the web app color tab to open the application in your browser. When the page loads, you should see the application displaying the color corresponding to the APP_COLOR value (in this case, pink). Once confirmed, click OK to proceed.
The image shows a KodeKloud practice test interface for Kubernetes, with a terminal and a question about setting an environment variable name in a pod container.
─────────────────────────────

5. Updating the Environment Variable for a Green Background

The next task is to update the pod configuration so that the background changes to green. This involves deleting and recreating the pod with the necessary modification while keeping the pod name unchanged.

5.1 Exporting the Current Pod YAML

First, verify the pod again:
Then, export the pod configuration to a file:

5.2 Deleting the Current Pod

Remove the running pod to make way for the updated configuration:

5.3 Modifying and Applying the Pod Configuration

Open the exported pod.yaml file in your favorite text editor, such as using vi:
Locate the env section under the container definition and change the value of APP_COLOR from pink to green. Save your modifications. Apply the updated configuration:
Finally, verify that the pod is running and that the background has changed to green.
The image shows a KodeKloud practice test interface for Kubernetes, instructing to update a pod's environment variable to display a green background.
─────────────────────────────

6. Listing ConfigMaps in the Default Namespace

To determine how many ConfigMaps are available in the default namespace, run:
The expected output is:
This output shows there are two ConfigMaps. ─────────────────────────────

7. Identifying the Database Host in the ConfigMap

Next, identify the database host by inspecting the ConfigMap named db-config:
Within the Data section of the output, you might find:
Here, DB_HOST is set to SQL01.example.com. ─────────────────────────────

8. Creating a New ConfigMap for the Webapp-Color Pod

Create a new ConfigMap named webapp-config-map that defines the APP_COLOR variable with a value of darkblue by executing:
Verify that the new ConfigMap has been created successfully. ─────────────────────────────

9. Updating the Pod to Use the New ConfigMap

The next step is to update the webapp-color pod so that it sources the APP_COLOR environment variable from the new ConfigMap.

9.1 Deleting the Existing Pod

Delete the current pod with this command:

9.2 Modifying the Pod YAML

Update the pod.yaml file to reference the ConfigMap rather than using a hard-coded environment variable value. Modify the container specification under the env section as follows:
Save your changes and apply the updated file:
After applying the configuration, verify that the pod is running and displays a background color of darkblue. ─────────────────────────────

10. Verifying the Updated Web Application

Finally, open the web app color interface once more and refresh the page. Confirm that the background has successfully changed to darkblue. When this change is verified, click OK to complete the exercise. ─────────────────────────────
This concludes the assignment for the ConfigMap lab session.
Ensure that you carefully check the environment variable sections in both the pod description and the YAML file when making updates to avoid configuration errors.

Watch Video