Skip to main content
In this lesson, we explore a common scenario encountered in Kubernetes where configuration changes (such as updates to ConfigMaps or Secrets) are not immediately reflected in running pods. This guide walks you through inspecting deployments, testing environment configurations, and troubleshooting issues related to environment variable updates.

Viewing Deployments in the Production Namespace

Begin by listing all deployments in the “production” namespace:

Inspecting the Web Application Deployment

Start with the web application deployment by examining its YAML definition:
Focus on the environment configuration where the web application receives its environment variables from a ConfigMap named web-message. To inspect this ConfigMap, retrieve its details by running:
The YAML output reveals a single key-value pair:

Testing the Web Application

To test the web application, set up port forwarding for the web service in a separate terminal:
With port forwarding active, verify the app’s response by sending a request:
The HTML response displays “Hello, World” – the message sourced from the web-message ConfigMap.

Updating the ConfigMap

Suppose you want to update the message from “Hello, World” to “Hello, KodeKloud.” Edit the ConfigMap with:
After saving the changes, you might expect that curling the web service returns the updated message. However, if you run:
the response still shows “Hello, World.” To further verify, execute the following command to inspect the pod’s environment variables:
Pods do not automatically update if a mounted ConfigMap changes. To see the updated configuration, you must restart the pod.
To update the running configuration, restart the deployment:
Then test the application again:
You should now see “Hello, KodeKloud” rendered as the new message.

Troubleshooting the Two-Tier Application

Next, let’s investigate the issue with the two-tier application, which is not becoming ready due to a failing readiness probe. The probe uses the following command to verify connectivity to the MySQL server:
This command prevents the pod from receiving traffic if a connection to the MySQL database fails.

Diagnosing the Readiness Probe Failure

To diagnose the problem, execute the following command to inspect the environment variables within the two-tier app pod:
Here, notice that the MYSQL_HOST variable is set to “mysql”. This value is provided by a secret named app-secrets. To inspect the secret, run:
Within the secret, the problematic field is encoded in base64. Verify the correct hostname by running:
This command outputs:
Even after correcting the secret, the pod might still use the old value because it was not restarted. To refresh the environment variables, restart the two-tier application deployment:
Once restarted, monitor the pod’s status and events to ensure it becomes ready and successfully connects to the MySQL server.

Final Thoughts

These examples illustrate that updating a ConfigMap or Secret does not automatically refresh the environment variables in running pods. Kubernetes requires a pod or deployment restart for changes to take effect. For large-scale environments with many pods, manually tracking which resources need a restart can be challenging.
Whenever you modify an external ConfigMap or Secret that is mounted onto pods, ensure that you restart the affected pods or deployments. This step is essential for the changes to be applied to the running configuration.
In an upcoming lesson, we will discuss strategies to manage these challenges more efficiently in your Kubernetes clusters. For more detailed Kubernetes concepts and best practices, check these resources:

Watch Video