Skip to main content
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.
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:
Updating dozens of Pod definitions manually increases the risk of misconfiguration. Instead, extract these values into a single ConfigMap.

ConfigMap Lifecycle

  1. Create a ConfigMap
  2. 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:
From a properties file (each file entry becomes a key):

Declarative (YAML) Approach

Define config-map.yaml:
Apply the configuration:
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:
Describe a specific ConfigMap:
Sample output:

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:
Each key in app-config appears as a separate file in /etc/config.

Comparing Injection Methods

Further Reading

References

Watch Video