ConfigMaps and Secrets
What You'll Learn
You'll learn how to externalize application configuration and sensitive data from container images using Kubernetes ConfigMaps and Secrets, keeping your deployments portable and secure.
Why Externalize Configuration?
Hardcoding configuration values or passwords directly into container images is a terrible practice. It means rebuilding images for every environment change, storing secrets in version control, and losing flexibility. ConfigMaps and Secrets solve this by separating configuration from code.
ConfigMaps: Non-Sensitive Configuration
ConfigMaps store configuration data as key-value pairs or entire files that Pods can consume. Think of them as external configuration files that Kubernetes manages for you.
Common use cases:
- Application settings (database URLs, feature flags)
- Configuration files (nginx.conf, application.yaml)
- Environment-specific values (API endpoints that differ between dev/prod)
ConfigMaps can be injected into Pods as environment variables or mounted as files in volumes.
Secrets: Sensitive Data
Secrets work similarly to ConfigMaps but are designed for sensitive information like passwords, API tokens, and SSH keys. Kubernetes stores Secrets in a base64-encoded format (note: not encrypted by default, but can be with additional configuration).
Use Secrets for:
- Database credentials
- TLS certificates
- OAuth tokens
- Private keys
The Power of Externalization
By using ConfigMaps and Secrets, you build one container image that runs everywhere. The same image in development, staging, and production—only the injected configuration differs. This dramatically reduces deployment risks and simplifies your CI/CD pipeline.
Think of it like a universal phone charger: the device (container) stays the same, but you plug it into different outlets (ConfigMaps/Secrets) depending on location.
Key Takeaway: ConfigMaps and Secrets externalize configuration and credentials from container images, making deployments portable, secure, and environment-agnostic without rebuilding images.