0
0
Kubernetesdevops~30 mins

Using ConfigMaps as environment variables in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Using ConfigMaps as Environment Variables in Kubernetes
📖 Scenario: You are deploying a simple web application on Kubernetes. You want to manage configuration settings like the app's greeting message using ConfigMaps. This way, you can change the message without changing the app code.
🎯 Goal: Create a ConfigMap with a greeting message, then configure a Pod to use this ConfigMap as environment variables. Finally, verify the Pod prints the greeting message from the ConfigMap.
📋 What You'll Learn
Create a ConfigMap named app-config with a key GREETING and value Hello, Kubernetes!
Create a Pod named greeting-pod that uses the app-config ConfigMap as environment variables
The Pod should run a container using the busybox image and print the GREETING environment variable
Verify the Pod output shows the greeting message from the ConfigMap
💡 Why This Matters
🌍 Real World
ConfigMaps let you separate configuration from code in Kubernetes. This helps you change app settings without rebuilding containers.
💼 Career
Knowing how to use ConfigMaps as environment variables is a key skill for Kubernetes administrators and DevOps engineers managing cloud-native apps.
Progress0 / 4 steps
1
Create the ConfigMap with the greeting message
Create a ConfigMap named app-config with a key GREETING and value Hello, Kubernetes! using the kubectl create configmap command.
Kubernetes
Need a hint?

Use kubectl create configmap with --from-literal to add the key and value.

2
Create the Pod manifest using the ConfigMap as environment variables
Create a Pod manifest YAML named greeting-pod.yaml with a Pod named greeting-pod. Use the busybox image and set the environment variable GREETING from the ConfigMap app-config using envFrom.
Kubernetes
Need a hint?

Use envFrom with configMapRef to load all keys from the ConfigMap as environment variables.

3
Apply the Pod manifest to create the Pod
Use the command kubectl apply -f greeting-pod.yaml to create the Pod named greeting-pod in the cluster.
Kubernetes
Need a hint?

Use kubectl apply -f greeting-pod.yaml to create or update the Pod from the YAML file.

4
Check the Pod logs to see the greeting message
Run kubectl logs greeting-pod to display the logs of the Pod. The output should show the greeting message Hello, Kubernetes! from the ConfigMap environment variable.
Kubernetes
Need a hint?

Use kubectl logs greeting-pod to see the output printed by the container.