ConfigMaps and Secrets
Separate configuration from images and inject it as env or files.
What you will be able to do
- Keep images environment-agnostic.
- Use ConfigMaps for non-secret values.
- Use Secrets for credentials.
- Prefer file mounts for larger configuration.
In plain English
ConfigMaps hold non-sensitive configuration; Secrets hold sensitive values. Both can be mounted as files or injected as environment variables. Secrets are base64-encoded, not encrypted by default, so enable encryption at rest.
apiVersion: v1
kind: ConfigMap
metadata:
name: web-config
data:
APP_ENV: production
LOG_LEVEL: info
---
apiVersion: v1
kind: Secret
metadata:
name: web-secret
type: Opaque
stringData:
DATABASE_URL: postgres://app:secret@db:5432/appYour turn
MediumInject an environment variable
Add an env var APP_ENV from a ConfigMap key named APP_ENV.
YAML · starter
env: []Check your understanding before moving on.
Knowledge checkQuestion 1
Are Kubernetes Secrets encrypted by default?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.