Kubernetes helps separate application artifacts from environment-specific settings, which is essential for portability and safer delivery.
ConfigMaps and Secrets are not interesting only because they exist. They matter because they reduce hard-coded environment assumptions.
Beginners often treat configuration as string replacement. Professionals think about rotation, scope, exposure, and deployment safety.
This topic is really about moving configuration out of the image while keeping environment behavior controlled.
If configuration is baked directly into images or scattered across ad hoc scripts, teams lose portability and increase release mistakes. The same artifact should ideally be reusable across environments with controlled configuration changes.
This principle is one reason platform workflows become more manageable over time: environment values stop being hidden inside artifacts.
Secrets are not just another configuration category. They carry risk because accidental exposure can have serious consequences for systems and users. That means handling them carelessly in manifests, logs, or build artifacts is dangerous.
Professionals think not only about where secrets are stored, but also about who can read them, how they are rotated, and how they move through workflows.
Build one immutable image and provide environment-specific values at deployment time. ConfigMaps hold non-sensitive configuration such as feature flags, URLs, or log levels. Secrets hold sensitive bytes such as passwords or tokens, but base64 encoding is not encryption. Both can be exposed as environment variables or mounted files.
Environment variables are simple but are fixed when the process starts and may appear in diagnostics. Mounted ConfigMap and Secret volumes can update, although applications must watch or reload the files and propagation is not instantaneous. Choose the delivery method based on the application behavior instead of assuming updates are automatic.
Keep development, staging, and production differences in deployment configuration rather than separate images. Use namespaces, overlays, Helm values, or another controlled rendering workflow. Render and validate manifests before applying them, and ensure required keys fail deployment clearly rather than silently using dangerous defaults.
A mature platform makes configuration intent visible. Teams should know which settings differ by environment, which ones are sensitive, and what values a workload truly requires to start correctly.
That clarity reduces debugging pain because misconfiguration becomes easier to spot and reason about.
Separate non-sensitive settings into a ConfigMap and credentials into a Secret, mount them deliberately, and trigger a controlled rollout when their content changes.
Base64 is encoding, not encryption. Environment variables may appear in diagnostics, and mounted values do not always cause applications to reload automatically.
Test rotation as a lifecycle, not merely as a manifest update. Create a new credential version, confirm that the workload can read it, restart or reload consumers in controlled batches, and keep the previous version valid until every replica has moved. Then revoke the old value and verify failed authentication is visible through metrics and alerts. This prevents a routine secret change from becoming an avoidable outage.
Verification must use evidence that matches the concept. Verify RBAC access, encryption-at-rest configuration, Pod template checksum, rollout revision, and that logs never print secret values. Repeat the check after deliberately introducing the failure, then after the fix. The contrast between those runs is the part that turns a definition into practical understanding.
Use an external secret manager or operator when credentials require centralized rotation, audit, and short lifetimes. Restrict Secret access with RBAC, enable encryption at rest for Kubernetes API data, and protect backups containing cluster state. Avoid broad list permission because listing Secrets exposes every value in the namespace.
Rotation is a rollout process. Create a new credential, allow both old and new versions temporarily, update consumers in controlled batches, verify successful use, then revoke the old version. Add checksums or version annotations to Pod templates when configuration changes should trigger a rollout. Test rollback while both credential versions are still valid.
Apply policy to prevent privileged Pods, unapproved registries, missing resource settings, or plaintext sensitive values. Sign deployment artifacts and separate authoring, approval, and runtime permissions. Monitor failed authentication, configuration reloads, rollout health, secret age, and access audit events without logging secret contents.
Values injected as environment variables are fixed for the life of the container; changing the ConfigMap or Secret does not rewrite the process environment. Projected volume files can update eventually, but applications must watch or reload them safely, and a subPath mount does not receive the same automatic updates. Choose either explicit Pod rollout or tested live reload rather than assuming every delivery method behaves alike.
Use immutable, versioned configuration when reproducibility matters. Reference the version from the Pod template so a change creates a new rollout and rollback restores the old reference. For mutable objects, add a checksum annotation or another release mechanism that changes the template. Confirm which controller owns that behavior instead of relying on a convention hidden in one deployment tool.
envFrom is convenient for importing many keys but makes collisions and newly added values less visible. Prefer explicit key references for critical settings, validate required configuration at process startup, and use naming conventions that prevent one ConfigMap or Secret from silently overriding another source.
Base64 in a Secret manifest is encoding, not encryption. Anyone who can read the API object can recover the value. Restrict RBAC, encrypt Kubernetes API data at rest, protect etcd backups, avoid committing plaintext or reversible encodings, and prefer short-lived workload identity over copied long-lived cloud keys where available.
This is a useful platform habit regardless of tooling detail.
Build one application image -> inject non-sensitive environment-specific config separately -> inject secrets through controlled secret handling -> keep the artifact itself portable
envFrom:
- configMapRef: {name: app-config}
- secretRef: {name: app-secrets}
metadata:
annotations:
checksum/config: '<rendered-checksum>'
Inject public settings and credentials through separate resources.
env:
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: app-config
key: log_level
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: database-credentials
key: password
Confirm both permissions and workload adoption.
kubectl auth can-i get secret/database-credentials --as=system:serviceaccount:app:api -n app
kubectl get deploy api -n app -o jsonpath=\"{.spec.template.metadata.annotations}\"
kubectl rollout status deployment/api -n app
kubectl get events -n app --sort-by=.metadata.creationTimestamp
It can, but that usually reduces portability and makes releases riskier. Separating it is generally healthier.
Because exposure can create immediate security risk, and rotation or access mistakes can break workloads or expose sensitive systems.
Explore 500+ free tutorials across 20+ languages and frameworks.