ConfigMaps let you decouple configuration artifacts from image content, so containerized applications are easily portable. With ConfigMaps you can store configuration data in key–value pairs and inject them into Pods as environment variables or mounted files.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
ConfigMaps are not designed for sensitive information. Use Secrets for credentials and tokens.
Why Use ConfigMaps?
Hard-coding environment variables in Pod specs is tedious when you maintain multiple workloads. Consider this example:ConfigMap Lifecycle
- Create a ConfigMap
- Inject it into your Pod
1. Creating a ConfigMap
Kubernetes supports both imperative and declarative creation methods.Imperative (kubectl) Approach
From literal key–value pairs:
Declarative (YAML) Approach
Defineconfig-map.yaml:
Use descriptive names and labels for each ConfigMap (e.g.,
app-config, mysql-config, redis-config) so you can manage them easily across environments.Inspecting ConfigMaps
List all ConfigMaps:2. Injecting ConfigMaps into Pods
You can consume ConfigMaps in two main ways:- As environment variables
- As files via a mounted volume
A. Environment Variables
Bulk Injection with envFrom
Inject all keys as environment variables:
Single Key Injection
Inject a specific key:B. File-based Injection
Mount ConfigMap entries as files inside the container:app-config appears as a separate file in /etc/config.
Comparing Injection Methods
| Injection Type | Use Case | Configuration Option |
|---|---|---|
| Bulk environment loading | Simple, all-in-one injection | envFrom.configMapRef |
| Single variable reference | Granular control per key | env.valueFrom.configMapKeyRef |
| File mounting | Applications reading configs as files | volumes.configMap |