Kubernetes Curriculum
What Are Configmaps
Every application needs configuration — database hostnames, API endpoints, feature flags, log levels, and environment-specific settings. Hardcoding this configuration inside the Docker image is wrong because the same image needs to run in dev, staging, and production with different settings.
ConfigMaps solve this. A ConfigMap is a Kubernetes object that stores non-sensitive configuration data as key-value pairs. You define the configuration once in a ConfigMap and inject it into Pods as environment variables, command-line arguments, or files — without changing the container image.
The Problem ConfigMaps Solve
Without ConfigMaps, your container image must bake in configuration:
This creates one image that only works in production. Development needs a different image. Staging needs another.
With ConfigMaps, the image is environment-agnostic:
Configuration comes from a ConfigMap at runtime:
The application reads DATABASE_HOST from environment — in dev it gets the dev database, in production it gets the production database. Same image. Same application code.
What a ConfigMap Stores
ConfigMaps store data as key-value pairs. The values can be:
Simple strings — environment variable values, port numbers, log levels:
Multi-line content — entire configuration files:
ConfigMap vs Secret
Never store passwords, API keys, or tokens in a ConfigMap — use Secrets for sensitive data.
ConfigMap Data Limits
ConfigMaps have a 1MB data limit. This is usually more than enough for configuration files. If you need more than 1MB of configuration data, reconsider whether configuration data belongs in Kubernetes objects at all — large blobs are better stored in S3 and fetched via init containers.
ConfigMap Immutability
For Kubernetes 1.21+, you can mark a ConfigMap as immutable. Immutable ConfigMaps:
- Cannot be modified after creation
- Reduce load on the API Server (no need to watch for changes)
- Prevent accidental configuration changes in production
When using immutable ConfigMaps, adopt a versioned naming convention: app-config-v1, app-config-v2, etc. Update the Deployment to reference the new version — this forces a Pod rollout.
Viewing and Managing ConfigMaps
Real-World ConfigMap Examples
Web Application Configuration
Nginx Configuration File
Summary
- ConfigMaps store non-sensitive configuration data as key-value pairs — simple strings and multi-line file content
- The same Docker image runs in all environments; ConfigMaps provide the environment-specific configuration at runtime
- ConfigMaps can hold individual values (for environment variables) and entire configuration files (for mounting as files into containers)
- Use Secrets for sensitive data (passwords, API keys) — never ConfigMaps
- ConfigMaps have a 1MB data limit — large configuration blobs belong in S3
- Mark ConfigMaps as
immutable: truein production to prevent accidental changes and reduce API Server load
In the next file, 02-creating-configmaps.md, you will learn all the ways to create ConfigMaps — from literal values, from files, from directories, and from YAML — with the trade-offs of each approach.