0
0
Kubernetesdevops~30 mins

Why configuration separation matters in Kubernetes - See It in Action

Choose your learning style9 modes available
Why Configuration Separation Matters in Kubernetes
📖 Scenario: You are managing a simple web application deployed on Kubernetes. You want to keep your application code separate from its configuration settings, such as environment variables and resource limits. This helps you update configuration without changing the application container image.
🎯 Goal: Learn how to separate configuration from application code by creating a Kubernetes Deployment and a ConfigMap, then link them together. Finally, display the configuration inside the running container.
📋 What You'll Learn
Create a ConfigMap with specific configuration data
Create a Deployment that uses the ConfigMap as environment variables
Verify the configuration is accessible inside the container
💡 Why This Matters
🌍 Real World
Separating configuration from code is a best practice in Kubernetes to manage settings independently and securely.
💼 Career
DevOps engineers and SREs often create and manage ConfigMaps and Secrets to configure applications in production environments.
Progress0 / 4 steps
1
Create a ConfigMap with app configuration
Create a Kubernetes ConfigMap named app-config with these exact key-value pairs: APP_MODE=production and LOG_LEVEL=info.
Kubernetes
Need a hint?

Use kind: ConfigMap and put your key-value pairs under data:.

2
Create a Deployment using the ConfigMap
Create a Kubernetes Deployment named web-app with one replica. Use the image busybox and set environment variables APP_MODE and LOG_LEVEL from the ConfigMap app-config.
Kubernetes
Need a hint?

Use envFrom: with configMapRef: to load all keys as environment variables.

3
Add a command to print environment variables
Modify the Deployment's container command to print the environment variables APP_MODE and LOG_LEVEL using sh -c and then sleep. Use the command: sh -c "echo APP_MODE=$APP_MODE LOG_LEVEL=$LOG_LEVEL && sleep 3600".
Kubernetes
Need a hint?

Use command: ["sh", "-c", "..."] to run multiple shell commands.

4
Display the configuration output
Run kubectl apply -f on your YAML file and then run kubectl logs on the pod created by the web-app Deployment to display the output showing APP_MODE=production and LOG_LEVEL=info.
Kubernetes
Need a hint?

Use kubectl logs on the pod to see the printed environment variables.