Skip to main content
In this lesson we’ll cover how to manage non-sensitive configuration data in Kubernetes using ConfigMaps. ConfigMaps let you extract environment variables and small configuration files out of Pod manifests and manage them centrally as key-value pairs. You can then inject them into Pods as environment variables or files. What you’ll learn:
  • How to create ConfigMaps (imperative and declarative)
  • How to inject ConfigMaps into Pods (envFrom, single env var, or mounted as files)
  • How to inspect ConfigMaps and best practices

Why use ConfigMaps?
  • Centralize configuration so many Pods can reuse the same values.
  • Keep Pod manifests focused on application runtime rather than configuration.
  • Separate code and configuration to simplify updates and rollouts.
ConfigMaps are not a replacement for Secrets. Do not store passwords, tokens, or other sensitive data in ConfigMaps.

Quick example: Pod with inline environment variable (before extracting to a ConfigMap)
As your deployment scale grows, embedding config values directly in Pod manifests becomes hard to manage. Move those key-value pairs into a ConfigMap to centralize updates.
Creating ConfigMaps: two approaches Imperative examples Create a ConfigMap from literals:
Create from a file (key defaults to filename):
Declarative example File: configmap.yaml
Apply it:
Name your ConfigMaps descriptively (for example: app-config, mysql-config, redis-config) — you will reference these names when injecting them into Pods.
View ConfigMaps List ConfigMaps:
Example output:
Describe a ConfigMap to inspect keys and values:
Abridged output:

Injecting ConfigMaps into Pods Common methods to provide ConfigMap data to containers:
  1. envFrom — inject all keys as environment variables
  2. valueFrom (configMapKeyRef) — inject a single key as an environment variable
  3. Volume mount — expose keys as files inside the container
Method 1: Inject all keys as environment variables (envFrom) File: pod-envfrom.yaml
Apply:
Result: The container receives APP_COLOR=blue and APP_MODE=prod as environment variables. Method 2: Inject a single environment variable from a ConfigMap key (valueFrom) Use this when you only need specific keys as environment variables.
Method 3: Mount ConfigMap data as files (volumes) Mount a ConfigMap into a path inside the container. Each ConfigMap key becomes a file with the key name, and its value becomes file contents.
Inside the container:
  • /etc/app-config/APP_COLOR contains blue
  • /etc/app-config/APP_MODE contains prod
Pick the injection method based on your app’s needs:
  • envFrom — convenient when many keys map directly to environment variables
  • valueFrom — precise control for individual variables
  • Volume mount — when the app expects config files or you need to provide structured files
Table: Injection method summary
Best practices and tips
  • Do not store secrets (passwords, tokens) in ConfigMaps — use Kubernetes Secrets instead.
  • Use declarative YAML files for ConfigMaps when you want auditability and GitOps workflows.
  • Prefer descriptive ConfigMap names tied to their consumer or service.
  • When updating a ConfigMap that a Pod uses as environment variables, you must recreate or restart the Pod to pick up env changes. Volume-mounted ConfigMap updates are reflected automatically in many cases, but behavior can depend on the application and how it reads files.

Summary
  • ConfigMaps store non-sensitive configuration as key/value pairs.
  • Create them imperatively with kubectl create configmap (--from-literal, --from-file) or declaratively with a YAML manifest.
  • Inject them into Pods using:
    • envFrom (all keys as env vars),
    • env + valueFrom (configMapKeyRef) for a single key, or
    • mount as files using a configMap volume.
  • Use Secrets for sensitive data.
Practice: create a ConfigMap, inspect it with kubectl describe, and try each injection method to see how your application reads configuration. Links and references

Watch Video

Practice Lab