Managing Application Configuration with Kubernetes ConfigMaps
Stop hardcoding settings in your containers. Learn to use Kubernetes ConfigMaps to decouple configuration from code for more portable, flexible deployments.

Previously in this course, we explored injecting environment variables in Kubernetes pods. While simple environment variables work for one-off settings, they quickly become unmanageable as your project grows. This lesson introduces ConfigMaps, the primary Kubernetes mechanism for managing application configuration at scale.
The Problem: Decoupling Configuration from Code
In traditional development, you might bake configuration files directly into your Docker image. This is a common pitfall because it forces you to rebuild the entire image whenever a single setting—like a database URL or a feature flag—changes.
To build portable, production-ready applications, we follow the principle of decoupling. Your container image should be immutable (the same code runs in development, staging, and production), while the configuration injected into the container adapts to the environment. ConfigMaps allow you to store these non-sensitive settings as key-value pairs or entire configuration files outside of your Pod definition.
Understanding the ConfigMap Object
A ConfigMap is a standalone Kubernetes resource. Once created, it exists in the cluster independently of any specific Pod. You can then "mount" or "inject" this data into your Pods, allowing the application to read the settings as if they were local files or environment variables.
Worked Example: Creating and Using a ConfigMap
Let's say our web application needs a specific app-settings.json file. Instead of hardcoding it, we will define it in a ConfigMap.
1. Create the ConfigMap
Save the following to app-config.yaml:
YAMLapiVersion: v1 kind: ConfigMap metadata: name: web-app-config data: app-settings.json: | { "debug": true, "theme": "dark", "api_endpoint": "https://api.example.com" } log_level: "info"
Apply it with kubectl apply -f app-config.yaml.
2. Reference the ConfigMap in your Pod
You can now update your Pod manifest to use this data. Here, we mount the app-settings.json key as a file inside the container:
YAMLapiVersion: v1 kind: Pod metadata: name: config-demo-pod spec: containers: - name: web-server image: nginx volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: web-app-config
When this Pod starts, the file /etc/config/app-settings.json will exist inside the container, populated with the data from our ConfigMap.
Comparison: ConfigMap vs. Environment Variables
| Feature | Environment Variables | ConfigMap |
|---|---|---|
| Use Case | Single, simple values | Large files or sets of values |
| Updates | Requires Pod restart | Can be updated without restart (if mounted as volume) |
| Organization | Flat key-value | Can represent complex file structures |
Hands-on Exercise
- Create a ConfigMap named
my-app-configcontaining a keymessagewith the valueHello from Kubernetes!. - Create a Pod manifest that uses
envFromto inject the entire ConfigMap into the container as environment variables. - Apply both and use
kubectl execto runenvinside the pod, verifying thatMESSAGE=Hello from Kubernetes!appears in the output.
Common Pitfalls
- ConfigMap Dependency: If a Pod references a non-existent ConfigMap, the Pod will fail to start and stay in a
CreateContainerConfigErrorstate. Always create the ConfigMap first. - Sensitive Data: Never put passwords or API keys in a ConfigMap. ConfigMaps are stored in plain text in
etcdand are not encrypted. Use Secrets for sensitive information instead. - Case Sensitivity: Kubernetes keys in ConfigMaps are case-sensitive. Ensure your application code expects the exact key name you defined.
FAQ
Can I update a ConfigMap while the Pod is running? Yes. If you mount a ConfigMap as a volume, Kubernetes will eventually update the file inside the container. However, your application code must be written to watch for file changes or restart to pick up the new values.
Does changing a ConfigMap restart my Pod? No. Kubernetes does not automatically restart Pods when a ConfigMap is updated. If your application doesn't watch for file changes, you will need to manually delete the Pod to force a restart with the new configuration.
Recap
Decoupling configuration from application code is a cornerstone of modern infrastructure. By using ConfigMaps, we keep our container images generic and portable, pushing environment-specific details into the cluster's management layer.
Up next: We will explore how to diagnose and fix issues when your pods fail to start in Troubleshooting Pod Crashes.
Work with me

CI/CD Pipeline & Docker Containerization
Ship with confidence: automated CI/CD pipelines and Docker setups so every push is tested and deployed — no more manual, error-prone releases.

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.


