ConfigMaps and Secrets: Managing Application Configuration in Kubernetes
Learn how Kubernetes ConfigMaps and Secrets work, how updates reach pods, and how to control Secret access and protect data at rest.
ConfigMaps hold non-sensitive settings; Secrets hold credentials and other sensitive values. Kubernetes base64-encodes Secret data, but that does not encrypt or protect it by itself. This guide covers API permissions, encryption at rest, mounted files, updates, rotation, and the role of external secret providers.
ConfigMaps and Secrets: Managing Application Configuration in Kubernetes
Applications need settings that vary by environment, such as database addresses and feature flags. Credentials and keys need tighter handling than those settings. Kubernetes has two namespaced resources for supplying these values to pods: ConfigMaps and Secrets.
The examples target Kubernetes 1.37.1. The links use Kubernetes’ current documentation; see the official Kubernetes 1.37 release page for release information.
For Kubernetes basics, see the Kubernetes fundamentals post. For advanced patterns like external secret operators, read the Advanced Kubernetes post.
Introduction
ConfigMaps and Secrets provide configuration to containers as environment variables or files. Use ConfigMaps for non-sensitive settings such as feature flags and config files. Use Secrets for credentials, tokens, and private keys.
Secret values in Kubernetes are base64-encoded by default. Base64 is an encoding, not encryption. Without encryption at rest, Secret data in etcd can be read by someone who can access the datastore or its backups. API access is controlled by authentication and authorization; it is not granted to every cluster user automatically. A Secret volume also does not hide its contents from processes in the container or from a node administrator.
This guide covers how to create and mount these resources, how updates reach a running app, and what protects Secret data in the API, etcd, and on a node. It also explains where an External Secrets Operator (ESO) fits: ESO copies values from a configured provider into Kubernetes. Provider-side encryption and rotation depend on that provider and its configuration; etcd encryption and API audit events must be configured separately.
When to Use / When Not to Use
Use ConfigMaps when
ConfigMaps work well for non-sensitive configuration that changes between environments: feature flags, environment variables, application settings, and configuration files like nginx.conf or config.yaml.
Pods in the same namespace can use the same ConfigMap. Keeping settings outside the image lets you deploy that image in dev, staging, and prod.
Use Secrets when
Use Secrets for credentials, API keys, OAuth tokens, TLS private keys, and other sensitive values.
Kubernetes encodes Secret values as base64 when it returns them through the API. That does not encrypt them. Configure encryption at rest for etcd, restrict API permissions, protect etcd backups, and limit node access. An external secret provider can be useful, but using ESO alone does not encrypt the Kubernetes Secret or provide an audit trail or rotation; those depend on the provider and its configuration.
Skip ConfigMaps for
Do not put credentials or private keys in a ConfigMap. ConfigMaps do not have built-in version history or audit records; those require your source-control and audit setup.
Assume people with read access to a namespace can inspect its ConfigMaps. Keep sensitive data out of them, and review who can read them.
If a value should not appear in a YAML export or Git history, it does not belong in a ConfigMap. A Secret is the right Kubernetes resource for that value, but it still needs access controls and protection at rest.
Do not rely on native Secrets without additional controls
By default, Kubernetes stores Secret data unencrypted in etcd. API requests still require authentication and authorization, but a principal allowed to get, list, or watch Secrets can read their values. list and watch are especially broad: they expose Secret data across the namespace. Someone with access to etcd or an unprotected backup can also read unencrypted values.
In a multi-tenant cluster, a broad role can expose data beyond the workload that needs it. Kubernetes scopes Secrets to namespaces, and RBAC controls API access within those boundaries; audit every binding that grants Secret permissions.
For sensitive workloads, configure encryption at rest for Secrets in etcd and use narrowly scoped RBAC. Enabling encryption does not protect a Secret already copied into a pod, exposed through a node, or included in an etcd backup made before encryption. After enabling a provider, follow the documented migration procedure to rewrite existing Secrets. Rotation and audit records need their own process and configuration.
| Scenario | Native Secrets | Recommendation |
|---|---|---|
| Local, single-user development | Possible | Use dummy credentials; avoid committing Secret values |
| Shared development cluster | Possible | Restrict API access and use non-production credentials |
| Staging or production | Possible | Enable encryption at rest, least-privilege RBAC, and a rotation plan |
| Workloads with audit requirements | Possible | Configure API/provider audit logging to meet the applicable policy |
ConfigMap/Secret Injection Flow
flowchart TD
CM["ConfigMap<br/>or Secret"] -->|kubectl apply| K8s["Kubernetes API Server"]
K8s -->|Store| etcd[etcd datastore]
K8s -->|Watch| Pod[Pod with Container]
Pod -->|Mount as| Volume["/etc/config<br/>or /run/secrets"]
Pod -->|Inject as| EnvVar["Environment<br/>Variables"]
For ordinary ConfigMap and Secret volume mounts, kubelet eventually projects updates into the mounted files. The application must reopen or reload those files to use the new values. Environment variables are set when the container starts and do not change when the resource changes. A subPath mount does not receive projected updates. See the official Secret documentation and ConfigMap documentation.
ConfigMap Creation and Usage Patterns
ConfigMaps hold non-sensitive values as keys or files. You can create them from literal values, files, or directories.
Creating from literals
Pass --from-literal with a key=value pair to add an entry directly. The text before = is the key; the rest is its value. Repeat the flag for additional entries.
kubectl create configmap app-config \
--from-literal=ENVIRONMENT=production \
--from-literal=LOG_LEVEL=info \
--from-literal=MAX_CONNECTIONS=100
This creates a ConfigMap named app-config with three keys: ENVIRONMENT, LOG_LEVEL, and MAX_CONNECTIONS.
Creating from a file
kubectl create configmap nginx-config \
--from-file=nginx.conf
The filename becomes the ConfigMap key, and the file contents become its value.
Creating from a directory
Point --from-file at a directory to make each top-level file a ConfigMap key. Subdirectories and hidden files are skipped.
kubectl create configmap html-content \
--from-file=html/
If html/ contains index.html and about.html, the ConfigMap has two keys. This is useful when an application reads several separate files.
Defining in YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: production
data:
ENVIRONMENT: "production"
LOG_LEVEL: "info"
DATABASE_HOST: "postgres.database.svc.cluster.local"
DATABASE_PORT: "5432"
Injecting ConfigMap into Pods
You can inject ConfigMap values as environment variables or volume mounts.
Environment variables
apiVersion: v1
kind: Pod
metadata:
name: web-app
namespace: production
spec:
containers:
- name: web-app
image: nginx:1.25
envFrom:
- configMapRef:
name: app-config
With envFrom, all keys from the ConfigMap become environment variables. For selective injection, use env:
env:
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: app-config
key: LOG_LEVEL
- name: ENVIRONMENT
valueFrom:
configMapKeyRef:
name: app-config
key: ENVIRONMENT
Volume mounts
Mount ConfigMap values as files:
apiVersion: v1
kind: Pod
metadata:
name: web-app
spec:
containers:
- name: web-app
image: nginx:1.25
volumeMounts:
- name: config
mountPath: /etc/nginx/conf.d
readOnly: true
volumes:
- name: config
configMap:
name: nginx-config
items:
- key: nginx.conf
path: default.conf
With this setup, /etc/nginx/conf.d/default.conf contains the contents of the nginx.conf key from the ConfigMap.
Secret Types and Limitations
Secrets are namespaced Kubernetes objects. Their data values are base64-encoded in the API representation; that encoding does not protect the values. Only authenticated identities authorized by the API server can read them through the API, but permission to get, list, or watch Secrets grants access to their contents.
apiVersion: v1
kind: Secret
metadata:
name: db-credentials
namespace: production
type: Opaque
stringData:
username: REPLACE_WITH_A_NON_SECRET_PLACEHOLDER
password: REPLACE_WITH_A_NON_SECRET_PLACEHOLDER
These values are placeholders, not credentials. stringData accepts plain text and Kubernetes converts it to data when storing the Secret. Do not put real values in manifests committed to Git. If you manage a Secret directly, use an approved secret-management workflow that does not put its values in shell arguments or command history.
Kubernetes Secret types
| Type | Use Case |
|---|---|
| Opaque | Arbitrary key-value pairs |
| kubernetes.io/tls | TLS certificates |
| kubernetes.io/dockerconfigjson | Docker registry credentials |
| kubernetes.io/basic-auth | Basic auth credentials |
TLS Secret
apiVersion: v1
kind: Secret
metadata:
name: tls-cert
namespace: production
type: kubernetes.io/tls
data:
tls.crt: <BASE64_CERTIFICATE_PLACEHOLDER>
tls.key: <BASE64_PRIVATE_KEY_PLACEHOLDER>
The values above are illustrative placeholders and are not valid certificate data. Do not store a real private key in a source-controlled manifest.
Mounting vs Environment Variables
Both approaches work, but they have different properties:
| Aspect | Environment Variables | Volume Mounts |
|---|---|---|
| Update propagation | Container restart required for new values | Projected files update eventually; the app must reload them |
| Exposure | May be visible through process inspection or diagnostics | File access is limited by container and file permissions, but the app and container users can read it |
| Format | Single values | Files |
| Size limit | Not suitable for large configs | Good for config files |
Environment variables suit simple values that only need to be read at container startup. Volume mounts are useful for files and values that the application can reload. Neither method encrypts the value inside the container or protects it from a process with access to that container.
Kubelet eventually projects changed ConfigMap or Secret values into an ordinary volume. There is no fixed update interval configured in the resource. The application must detect and reload changed files; environment variables remain unchanged until the container restarts. A subPath mount does not receive projected updates.
External Secret Operators
Kubernetes does not encrypt Secret data in etcd by default, and each Secret is limited to 1 MiB. Native Secrets do not fetch values from an external provider; an operator can synchronize them.
ESO reads from a configured provider and writes selected values to a Kubernetes Secret. The provider may offer encryption for its own storage, audit logs, or rotation, depending on its configuration. Encryption of the Kubernetes Secret in etcd and API audit events require separate configuration. ESO’s refresh interval controls when it checks for changes; ESO does not rotate the source credential by itself.
External Secrets Operator example
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: database-secrets
namespace: production
spec:
refreshInterval: 1h
secretStoreRef:
name: vault-backend
kind: ClusterSecretStore
target:
name: db-secrets
creationPolicy: Owner
data:
- secretKey: password
remoteRef:
key: production/database
property: password
This ExternalSecret asks the configured Vault store for the password property and writes it to a Kubernetes Secret named db-secrets. With refreshInterval: 1h, ESO checks the provider on that schedule. Rotation must happen in the provider, and the application still needs to reload the updated Secret or restart.
ESO supports AWS Secrets Manager, Azure Key Vault, Google Secret Manager, HashiCorp Vault, and other providers. Check the ESO and provider documentation for the API version and features supported by the versions you deploy.
Security Hardening for Secrets
Protecting a Secret requires controls at several points: API access, etcd storage and backups, and the node and container that receive the value.
Enable encryption at rest
Configure the API server to encrypt Secrets before writing them to etcd. This example uses a placeholder key; keep real encryption keys in a protected control-plane configuration or key-management system, not in application source control.
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
- secrets
providers:
- aesgcm:
keys:
- name: key1
secret: <BASE64_ENCODED_32_BYTE_KEY_PLACEHOLDER>
- identity: {}
Configure the API server with the encryption configuration:
--encryption-provider-config=/path/to/encryption-config
Enabling encryption affects new writes. Existing Secrets remain in their previous storage format until rewritten through the API after the provider is active. Follow the control-plane migration procedure and verify the storage state before treating old objects or backups as encrypted. Encryption at rest does not protect values already mounted into pods or accessible to a node administrator. See the official encryption guide.
Restrict API access with RBAC
Grant only the access the workload needs. In particular, list and watch let a client read Secret data across the namespace; they are not safe substitutes for access to one object. This example grants a dedicated ServiceAccount get access to one Secret:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: production
name: read-db-credentials
rules:
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["db-credentials"]
verbs: ["get"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: app-secret-reader
namespace: production
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: app-read-db-credentials
namespace: production
subjects:
- kind: ServiceAccount
name: app-secret-reader
namespace: production
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: read-db-credentials
Set spec.serviceAccountName: app-secret-reader on a pod only if the application calls the Kubernetes API to read that Secret. A pod that uses secretKeyRef or mounts a Secret volume does not need API read permission for the Secret; kubelet obtains and projects the referenced value. If the app does not need to call the API, disable automatic token mounting for that pod or ServiceAccount.
Review effective permissions for users, groups, and ServiceAccounts, including permissions inherited through ClusterRoles and RoleBindings. Check the managed control plane’s authorization configuration through its provider, or review the API server configuration on a self-managed cluster. See RBAC good practices and the RBAC reference.
Protect the node and container
Mounting a Secret avoids placing its value in an environment variable, but it does not make the value inaccessible. The application and processes with sufficient access inside the container can read the mounted file. A user with root access to the node, or a privileged container with host access, can access Secret data delivered to that node. Limit node administration and privileged workloads, and run containers with only the filesystem and process permissions they need. The official Linux security guide describes these node-level risks.
On Linux, kubelet uses a memory-backed volume (tmpfs) for Secret volumes. This statement applies to those Linux volumes; it is not a guarantee for every platform or every copy of the data. Whether memory pages can reach persistent storage depends on swap, kernel support and settings, and the container runtime and node configuration. Secret data can also remain in etcd, logs, crash dumps, or application memory. See the Linux security guide for the swap and kernel qualifications.
Rotate values and reload the application
Updating a Secret does not make an application start using the new value automatically. Environment variables stay as they were when the container started. Ordinary Secret volume files are updated eventually, but the app must reread them; a subPath mount does not update. Plan how credentials will be changed at the provider, synchronized into Kubernetes if applicable, and loaded by the app. Test the full rotation path, including what happens if the old credential is revoked before all pods have reloaded.
Keep secrets out of logs, images, and Git
Treat secret handling as a deployment-source and build control. Do not bake credentials into Dockerfiles, build arguments, image layers, ConfigMaps, sample manifests, or application logs. Add secret scanning to CI for source changes and built images, block deployments that source credentials from unapproved places, and rotate any value that reaches logs, an image, or Git history. Removing a leaked value in a later commit does not remove it from the earlier history or image layers.
Consider third-party solutions
Native Kubernetes Secrets and external providers solve different parts of the problem. Choose a provider based on the access, audit, and rotation requirements of the workload.
HashiCorp Vault can issue short-lived credentials, manage leases, and record access when configured to do so. Its Kubernetes authentication method can let pods authenticate with ServiceAccount tokens instead of embedding a static Vault credential. Whether credentials rotate, expire, or produce the required audit records depends on the Vault setup and the secret engine.
AWS Secrets Manager, Azure Key Vault, and Google Secret Manager provide managed secret stores. ESO offers a Kubernetes resource for requesting values from supported providers; provider features and ESO synchronization are configured separately.
ESO does not require a Vault deployment. An ExternalSecret maps provider values into a Kubernetes Secret. Moving between providers may require changes to the store configuration, authentication, and provider-specific fields; do not assume the manifest will be identical.
Kubernetes audit events depend on API audit policy and control-plane configuration. A provider may also offer access logs, depending on its setup. Confirm what each system records and retain those logs according to your requirements; neither ESO nor a provider name alone guarantees a complete audit trail.
Trade-off Analysis
ConfigMap Mounting vs Environment Variables
| Aspect | Environment Variables | Volume Mounts |
|---|---|---|
| Update propagation | Requires container restart | Files update eventually; app must reload |
| Maximum size | Limited by the container environment | 1 MiB per ConfigMap or Secret |
| Application support | Most runtimes can read env vars | App must read and reload mounted files |
| Type safety | String values only | Can map to JSON, YAML files |
| Exposure | Can appear in process inspection or diagnostics | Readable by processes with access to the mounted file |
Native Secrets vs External Secret Operators
| Aspect | Native Kubernetes Secrets | External Secret Operators (ESO) |
|---|---|---|
| Encryption | Base64 encoding; etcd encryption must be configured | Provider storage and Kubernetes etcd encryption are configured separately |
| Rotation | Update the Secret and reload/restart the app | ESO syncs provider changes; provider rotation and app reload are separate |
| Audit logs | API audit policy and control-plane setup | Provider and Kubernetes audit configuration |
| Size limit | 1 MiB per Secret | Kubernetes Secret limit still applies |
| Integration | API resource in Kubernetes | ESO supports configured external providers |
ConfigMap Binary Data vs UTF-8 Data
| Aspect | UTF-8 Data (data) |
Binary Data (binaryData) |
|---|---|---|
| Encoding | UTF-8 strings directly | Base64-encoded binary content |
| Use case | UTF-8 configuration files and text | Non-UTF-8 binary data |
| Validation | Values must be valid UTF-8 | Base64 representation is decoded by Kubernetes |
| Size limit | 1 MiB total per ConfigMap | 1 MiB total per ConfigMap |
YAML vs kubectl create configmap
| Aspect | YAML (kubectl apply) |
kubectl create commands |
|---|---|---|
| Version control | Yes — declarative, reviewable | Imperative — not self-documenting |
| Drift detection | Yes | No |
| Reusability | Yes — with kustomize/helm overlays | Limited — hard to adapt for different envs |
| Speed | Slower to type | Faster for quick local dev |
For deployment configuration, declarative manifests and GitOps make changes reviewable. Keep real Secret values out of those manifests and source-control history.
Production Failure Scenarios
Secret Not Found at Pod Startup
If a Pod references a Secret that does not exist, kubelet cannot mount or inject the value and the container does not start until the Secret is available.
Symptoms: the Pod may remain in ContainerCreating, with a mount or missing-Secret message in its events.
Diagnosis:
kubectl describe pod <pod-name> -n <namespace>
kubectl get secret <secret-name> -n <namespace>
Mitigation: Ensure the Secret exists before creating the Pod. Use your deployment tool’s dependency ordering where needed.
ConfigMap Update Not Propagating to Pods
When a ConfigMap is updated, ordinary volume-mounted files eventually reflect the change. Environment variables remain unchanged until the container restarts.
Symptoms: Application uses stale configuration even after ConfigMap update.
Mitigation: Use a regular volume mount if the application can reload files, or roll out new Pods when configuration changes. subPath mounts do not receive projected updates.
Base64 Encoding Errors in Secrets
If a Secret manifest uses the data field, each value must be base64-encoded. An invalid value may be rejected or decode to something different than intended. The stringData field accepts plain text for manifest generation, but do not commit real credentials in a manifest.
Symptoms: the application rejects a credential or reads unexpected bytes.
Mitigation: Prefer a secret-management tool that writes values directly from an approved source. Avoid putting credentials in shell arguments, command history, or terminal output.
Anti-Patterns
Storing Secrets in ConfigMaps
Putting credentials in a ConfigMap makes them readable to anyone who can read that ConfigMap. Use a Secret resource or an external provider instead, with the same attention to access controls and storage protection.
ConfigMap values can appear in YAML exports, CI logs, dashboards, and etcd backups. If a ConfigMap contains a credential, treat it as exposed: rotate the credential and review where the value was copied.
Anyone with permission to list ConfigMaps in a namespace can read their contents. Use RBAC to restrict access to both ConfigMaps and Secrets, and avoid broad list or watch grants when a workload only needs a named object.
If sensitive data appears in a ConfigMap, rotate it and remove it from any exposed locations, including source history and logs.
Not Using binaryData for Non-UTF8 Content
The data field in a ConfigMap holds UTF-8 strings. Use binaryData for files that are not valid UTF-8. PEM certificates and keys are usually text files, but binary certificate formats and images may need binaryData.
When a file does not meet the UTF-8 requirement, put it in binaryData or store it outside a ConfigMap. Avoid printing decoded secret material while diagnosing an issue.
The binaryData field represents binary content using base64 in the API. For example, this command reads a ConfigMap’s binaryData field to a file:
kubectl get configmap my-cert --output jsonpath='{.binaryData.logo\.png}' | base64 -d > logo.png
This example uses a public, non-sensitive binary asset. Do not use a similar command to print or decode a real Secret into an unprotected terminal or file.
Copying Entire ConfigMap into Every Environment
Development, staging, and production often need different values. Maintain environment-specific ConfigMaps through overlays or Helm values so, for example, a development deployment does not point at a production endpoint.
Use Kustomize overlays or Helm values to inject environment-specific configuration.
Interview Questions
Expected answer points:
- ConfigMaps store non-sensitive values; Secrets store credentials and other sensitive values
- Secret values are base64-encoded in the API representation; base64 does not encrypt them
- Both resources can be mounted as files or referenced as environment variables
- Use RBAC and encryption at rest to protect Secret access and storage; a Secret may still be readable in a pod or on its node
Expected answer points:
- Use `envFrom` with `configMapRef` to inject all keys as environment variables
- Use `env` with `configMapKeyRef` for selective injection of specific keys
- Environment variables are set at pod startup — they do not update when the ConfigMap changes
- For dynamic updates, use volume mounts instead of environment variables
Expected answer points:
- Kubelet eventually projects the updated value into a regular volume; there is no update interval set in the ConfigMap
- The application must reread the file to use the new value
- Environment variables do not change until the container restarts, and `subPath` mounts do not receive projected updates
- A rollout controller can restart Pods when configuration changes if the application cannot reload files
Expected answer points:
- Base64 is an encoding, not encryption; Secret data is unencrypted in etcd by default
- A principal with `get`, `list`, or `watch` permission can read Secret values; etcd access can expose stored values too
- Configure encryption at rest and protect the encryption keys and backups
- After enabling encryption, rewrite existing Secrets through the API to migrate them
Expected answer points:
- ESO reads values from a configured provider and writes them into Kubernetes Secrets
- ESO does not itself provide encryption at rest, source credential rotation, or a complete audit trail
- Provider features, ESO refresh settings, Kubernetes encryption, and audit policy all need separate configuration
- The application still needs to reload or restart to use updated Secret values
Expected answer points:
- `data` accepts UTF-8 strings
- `binaryData` holds arbitrary bytes and represents them as base64 in the API
- When projected into a volume, the application receives the original file content
Expected answer points:
- If the application reads the Kubernetes API, create a namespaced Role with only `get` on `secrets` and `resourceNames: ["db-credentials"]`
- Bind that Role to a dedicated ServiceAccount with a RoleBinding
- Use `spec.serviceAccountName` for the API-reading pod and avoid broad `list` or `watch` grants
- A pod that only mounts a Secret or uses `secretKeyRef` does not need API read permission for that Secret
Expected answer points:
- Create an EncryptionConfiguration YAML with AES-GCM or another provider
- Pass the config to kube-apiserver via `--encryption-provider-config` flag
- New writes are encrypted according to the configured provider
- Rewrite existing Secrets through the API after enabling encryption to migrate stored objects
- Protect and rotate encryption keys using the control-plane procedure
Expected answer points:
- Opaque — arbitrary key-value pairs and the default type
- kubernetes.io/tls — TLS certificates and keys
- kubernetes.io/dockerconfigjson — Docker registry credentials
- kubernetes.io/basic-auth — basic authentication credentials
- This is not an exhaustive list; Kubernetes also defines other Secret types
Expected answer points:
- Dev, staging, and prod have different database URLs, API endpoints, and feature flags
- Copying the same ConfigMap means production URLs end up in dev, or debug flags in production
- Use Kustomize overlays or Helm values to inject environment-specific values
- GitOps workflows should treat ConfigMaps as code with environment-specific variants
Expected answer points:
- Verify the ConfigMap exists in the same namespace as the pod: `kubectl get configmap -n
` - Check the pod spec references the correct ConfigMap name and injection method (env vs volume)
- Use `kubectl describe pod
` to see events — look for ConfigMap or Secret not found errors - Verify key names match exactly — Kubernetes is case-sensitive for ConfigMap keys
Expected answer points:
- Both ConfigMaps and Secrets are limited to 1 MiB
- For very large configuration files, consider storing them in object storage and pulling them at runtime
- Large ConfigMaps impact etcd performance and kubectl response times
Expected answer points:
- Each key appears as a file under the configured mount path
- Each Secret key becomes a file containing the decoded value
- On Linux, Secret volumes are memory-backed; swap, kernel, and runtime settings affect persistence, and this does not protect copies in etcd
- Regular volume files update eventually, but the application must reread them; `subPath` mounts do not update
Expected answer points:
- Define how the credential is rotated at its source and, if used, synchronized into Kubernetes
- ESO can refresh a Kubernetes Secret from provider changes, but it does not rotate the source credential
- Environment variables require a container restart; mounted files require the app to reload them
- Test the rollout and revocation order so pods do not keep using an expired value
Expected answer points:
- No — ConfigMaps are namespace-scoped resources
- To share a ConfigMap across namespaces, you must create identical ConfigMaps in each namespace
- Operators can replicate ConfigMaps across namespaces if needed
- Consider an external config store if you need true cross-namespace shared configuration
Expected answer points:
- subPath allows mounting a single key from a ConfigMap as a specific file without exposing all keys
- It is useful for mounting config files that conflict with the directory structure of the container
- The major limitation is that when using subPath, the application does not receive automatic updates when the ConfigMap changes — the pod must be restarted
- subPath bypasses symlink updates that work with regular volume mounts, making it unsuitable for frequently-updated configuration
Expected answer points:
- Set `immutable: true` in the ConfigMap spec to prevent any changes after creation
- Kubelet does not need to watch an immutable ConfigMap for updates, which can reduce overhead when a cluster has many of them
- Use for configuration that must never change at runtime (security policies, feature flags, environment defaults)
- If you need to change an immutable ConfigMap, you must delete and recreate it — there is no update operation
Expected answer points:
- 1MB is the total size limit for both ConfigMaps and Secrets — large configurations must be split across multiple resources
- For application configs exceeding 1MB, consider storing them in object storage (S3, GCS) and pulling at startup or via init container
- For non-UTF-8 ConfigMap content, use `binaryData`; Secret values belong in a Secret's `data` or `stringData` fields
- Large ConfigMaps impact etcd performance and kube-apiserver response times — keep ConfigMaps small
Expected answer points:
- Multiple `envFrom` entries with different ConfigMaps merge all keys into environment variables — if keys conflict, one overwrites the other (order matters)
- Multiple volume mounts from different ConfigMaps create separate files in different directories — no merge, no conflict
- Volume mounts allow files to be updated dynamically; env vars do not update after pod start
- For config that needs to be updated at runtime, use volumes; for static initialization values, use env vars
Expected answer points:
- You can mount both ConfigMaps and Secrets as volumes in the same container, giving the application a unified `/etc/config` or `/run/secrets` directory structure
- Use projected volumes to combine multiple ConfigMaps and Secrets into a single mount point with specific file permissions
- Projected volumes allow you to map specific keys from each resource to specific file names, controlling exactly what the application sees
- The app reads both resources from one mount point, while non-sensitive settings remain in a ConfigMap and sensitive values remain in a Secret
Further Reading
- Kubernetes Documentation - ConfigMaps
- Kubernetes Documentation - Secrets
- External Secrets Operator Documentation
- Kubernetes Documentation - Encrypting Data at Rest
- Kubernetes Documentation - Linux Security
- Kubernetes Documentation - RBAC Good Practices
- Kubernetes Documentation - RBAC Reference
- Kubernetes 1.37 Release Information
Conclusion
Use this checklist when managing ConfigMaps and Secrets:
- Used ConfigMaps for non-sensitive configuration, Secrets for credentials and keys
- Limited Secret API permissions, including avoiding broad
listandwatchaccess - Enabled encryption at rest and rewrote existing Secrets after turning it on
- Protected etcd backups, node access, and privileged workloads
- Kept secret values out of logs, container images, and Git history; added CI scanning and deployment-source checks
- Confirmed how the application reloads or restarts after a Secret changes
- Configured provider-side rotation and audit logging where required; did not assume ESO supplies them
- Used ConfigMap
binaryDataonly for binary configuration; kept credentials in Secret resources or a provider - Tested application behavior when ConfigMap or Secret values change at runtime
- Ensured referenced Secrets exist before Pods start
Category
Related Posts
Kustomize for Kubernetes Configuration Management
Build and review Kubernetes overlays with Kustomize. Learn when to use bases, patches, and generators, and validate rendered manifests before applying them.
Container Security: Image Scanning and Vulnerability Risks
Implement comprehensive container security: from scanning images for vulnerabilities to runtime security monitoring and secrets protection.
Deployment Strategies: Rolling, Blue-Green, Canary
Compare and implement deployment strategies—rolling updates, blue-green deployments, and canary releases—to reduce risk and enable safe production releases.