Every application needs configuration, and every application has secrets. The database host is configuration. The database password is a secret. Kubernetes gives you two objects for these two jobs, ConfigMap and Secret, and they look almost identical. Both store key-value pairs. Both can be mounted into a pod as files or injected as environment variables. Both are created with similar commands and referenced from the same places in a manifest. That similarity is exactly why people mix them up, and mixing them up is how passwords end up in plain text in a repository.
The difference is not about the shape of the data. It is about intent, handling and risk. A ConfigMap says “this value is not sensitive, and anyone who can read the cluster can read it.” A Secret says “this value is sensitive, handle it carefully, restrict who can read it, and do not store it in plain text.” The most important fact in this whole article, and the one to remember if you remember nothing else, is this: base64 is not encryption. A Secret’s values are base64-encoded, which is an encoding, not a cipher. Anyone who can read the Secret can decode it in one command. Kubernetes does not encrypt Secrets by default, and treating base64 as security is the single most dangerous misunderstanding in this area.
This article explains both objects properly: what each one stores, how to create and use them, how they differ in practice, when to use which, and how to keep real secrets safe in a production cluster. The examples use Kubernetes v1.37, the current release line as of December 2026, with 1.38 planned for around 16 December 2026. The ConfigMap and Secret APIs have been stable since v1, so nothing here depends on a recent version.
What a ConfigMap Is and What It Is For
A ConfigMap is a Kubernetes object that stores non-confidential configuration data as key-value pairs. It exists to separate configuration from code. Instead of baking a database host, a feature flag or a log level into a container image, you put it in a ConfigMap and let the pod read it at runtime. The same image can then run in development, staging and production, each with a different ConfigMap. That separation is one of the core practices of twelve-factor applications, and it is the reason ConfigMaps exist.
ConfigMaps hold plain text. The values are stored exactly as you write them, readable by anyone with permission to read ConfigMaps in the namespace. That is fine, because the values are not sensitive: hostnames, ports, feature flags, log levels, timeouts, and the names of queues and buckets. If a value would cause harm in the wrong hands, it does not belong in a ConfigMap.
A ConfigMap can also hold whole files. You can store an nginx configuration file, an application properties file, or a JSON document as a single key whose value is the file contents. When the ConfigMap is mounted into a pod, each key becomes a file, and the application reads its configuration file exactly as if it had been baked into the image. This pattern is extremely common for applications that expect a configuration file on disk and cannot read environment variables. The official Kubernetes ConfigMap documentation covers the full set of creation methods, including generating ConfigMaps from directories and from environment files.
ConfigMaps have a size limit of 1 MiB per object, which is generous for configuration and far too small for anything else. If you find yourself approaching the limit, your configuration has grown into something else, probably a dataset or a set of templates, and it belongs in a volume or an object store instead. The limit also applies to Secrets, for the same reason: etcd, the cluster’s data store, is not a file server.
Create a ConfigMap from literals, from files, or from a manifest. The imperative commands are the fastest way to learn, and the manifest is the right way to work in production.
kubectl create configmap app-config \
--from-literal=APP_ENV=production \
--from-literal=LOG_LEVEL=info \
--from-literal=DB_HOST=postgres.db.svc.cluster.local
kubectl create configmap nginx-config --from-file=nginx.conf
kubectl get configmap app-config -o yaml
A manifest for the same ConfigMap looks like this, and it belongs in your repository, because configuration that is not sensitive can and should be versioned alongside the code that uses it.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
namespace: web
data:
APP_ENV: production
LOG_LEVEL: info
DB_HOST: postgres.db.svc.cluster.local
What a Secret Is and Why Base64 Is Not Encryption
A Secret is a Kubernetes object that stores sensitive data: passwords, API tokens, TLS certificates, SSH keys and OAuth credentials. It has the same key-value shape as a ConfigMap, but Kubernetes treats it differently in several ways, and those differences are the whole point of having a separate object.
First, the values are base64-encoded. When you create a Secret from a literal, kubectl encodes the value before storing it. When you read the Secret back, you see the encoded form, and you must decode it to read the original. This confuses many people into thinking the value is protected. It is not. Base64 is a way of representing binary data as text, not a way of hiding it. Decoding a base64 value takes one command, and anyone who can run kubectl get secret can do it. The encoding exists so that binary data such as certificates and keys can be stored safely in etcd, not to keep the data secret.
kubectl get secret db-credentials -o jsonpath='{.data.password}' | base64 --decode
echo
Second, Secrets are handled more carefully by the system. They are not written to disk on nodes by default when mounted as volumes, they are stored in tmpfs, which is memory, and they are removed when the pod stops. The API server can be configured to encrypt Secrets at rest in etcd, which is a real protection and one you should enable. And RBAC can restrict who can read Secrets separately from who can read ConfigMaps, which lets you give a developer access to configuration while keeping passwords out of their reach.
Third, Secrets have types. The type tells Kubernetes and the tools around it what kind of data the Secret holds, and it enables validation. The common types are Opaque, the default for arbitrary data; kubernetes.io/tls for a TLS certificate and key pair, which Ingress controllers consume directly; kubernetes.io/basic-auth for a username and password; kubernetes.io/ssh-auth for SSH credentials; and kubernetes.io/dockerconfigjson for registry credentials, which the kubelet uses to pull private images. Using the right type matters: an Ingress that expects a TLS Secret will not accept an Opaque one. The official Kubernetes Secret documentation lists every type and the fields each one requires, and it is the reference to check when a type behaves unexpectedly.
Create a Secret the same way you create a ConfigMap, but think before you type. A password passed with --from-literal on the command line is stored in your shell history, which is a leak in itself. Prefer --from-file, which reads the value from a file, or create the Secret from a manifest that is generated by a secrets manager and never committed to Git.
kubectl create secret generic db-credentials \
--from-literal=username=appuser \
--from-literal=password='change-me-in-production'
kubectl create secret tls web-tls \
--cert=tls.crt --key=tls.key
kubectl get secret db-credentials -o yaml
Never commit a Secret manifest to Git. A ConfigMap manifest belongs in a repository. A Secret manifest, with real values, is a credential leak the moment it is pushed. If you need a Secret in Git for GitOps, use a sealed secret, an external secrets operator, or a templating approach where the values are injected at deploy time from a vault. The rule is absolute: secrets do not go in version control, in any form, including base64, because base64 is not encryption and anyone who finds the file can decode it.
ConfigMap vs Secret: The Differences That Matter
Side by side, the two objects are easy to compare, and the comparison shows why you need both rather than one. The table below covers the differences that change real decisions.
| Aspect | ConfigMap | Secret |
|---|---|---|
| What it stores | Non-sensitive configuration: hosts, ports, flags, log levels | Sensitive data: passwords, tokens, certificates, keys |
| Encoding | Plain text, stored as written | Base64-encoded, which is not encryption |
| Encryption at rest | Not encrypted by default | Not encrypted by default; enable encryption in etcd explicitly |
| Size limit | 1 MiB per object | 1 MiB per object |
| Can hold files | Yes, a whole file as one key | Yes, certificates and keys as files |
| Safe in Git | Yes, configuration belongs in version control | No, never commit real secret values |
| RBAC | Readable by anyone with ConfigMap access | Can be restricted separately from ConfigMaps |
| Types | No types | Opaque, TLS, basic-auth, SSH, dockerconfigjson |
| Volume storage | Written to disk on the node | Stored in tmpfs memory, removed when the pod stops |
| Updates | Mounted volumes update automatically, with a delay | Mounted volumes update automatically, with a delay |
| Environment variables | Injected at pod start; changing them needs a restart | Injected at pod start; changing them needs a restart |
Two rows in that table deserve more attention. The first is updates. When a ConfigMap or Secret is mounted as a volume, the kubelet updates the files in the pod automatically when the object changes, usually within a minute or so. That sounds like live configuration, and it is, but only for applications that re-read their files. Most applications read configuration once at startup and never look again, so the updated file sits there unused until the pod restarts. If you need a configuration change to take effect, the reliable answer is to restart the pods, usually with kubectl rollout restart deployment/NAME. Do not assume a ConfigMap edit has taken effect just because the file changed.
The second is the environment variable row. Injecting configuration as environment variables is convenient, but the values are fixed at pod start. Changing the ConfigMap or Secret does nothing until the pod is recreated. Worse, environment variables are visible to any process that can inspect the pod, including through kubectl exec and, in some runtimes, through the process list. A Secret injected as an environment variable is easier to leak accidentally than one mounted as a file. Prefer volume mounts for sensitive values, and reserve environment variables for values that are genuinely not sensitive.
The practical test for choosing between them is a single question: if this value were published on the internet tomorrow, would it cause harm? If the answer is yes, it is a Secret. If the answer is no, it is a ConfigMap. When you are unsure, treat it as a Secret. The cost of over-protecting a value is small. The cost of under-protecting one can be a breach.
Using ConfigMaps and Secrets in a Pod
Both objects reach a pod in the same two ways: as environment variables, or as files in a mounted volume. The manifest below shows both, for a Deployment that needs a database host from a ConfigMap and a database password from a Secret. If you are still learning how Deployments are written, our Kubernetes Deployment YAML tutorial explains every field in a manifest like this one.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: myapp:1.4.0
env:
- name: APP_ENV
valueFrom:
configMapKeyRef:
name: app-config
key: APP_ENV
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: app-config
key: DB_HOST
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-credentials
key: password
volumeMounts:
- name: tls
mountPath: /etc/tls
readOnly: true
- name: app-files
mountPath: /etc/app
readOnly: true
volumes:
- name: tls
secret:
secretName: web-tls
- name: app-files
configMap:
name: app-config
There are two more ways to inject a whole object at once. envFrom loads every key in a ConfigMap or Secret as environment variables, which is convenient when the object has many keys and you want them all. volumeMounts with a whole ConfigMap or Secret mounts every key as a file in one directory. Both are shorter to write, and both hide which values the pod actually uses, which makes auditing harder. Prefer explicit references for anything important, and use the bulk forms only for objects whose entire contents the pod genuinely needs.
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: db-credentials
Two failure modes are worth knowing. If a pod references a ConfigMap or Secret that does not exist, the pod will not start. It stays in Pending or ContainerCreating with an event explaining that the object was not found. That is a safety feature: it is better for the pod to refuse to start than to start with missing configuration and fail in a confusing way. The second failure mode is subtler. If a key referenced in env does not exist in the object, the pod also fails to start, unless you mark the reference as optional with optional: true. Use optional references sparingly, because a pod that starts without a value it needs will fail later, in a harder place to diagnose.
Be careful with the order of creation. The ConfigMap or Secret must exist before the pod that references it is created. In practice this means applying your configuration manifests before your workload manifests, or keeping them in the same directory and applying the whole directory at once, which kubectl handles in an order that usually works but is not guaranteed. If a deploy fails because a ConfigMap is missing, create the ConfigMap and re-apply: the failure is recoverable and the error message names the missing object.
Keeping Real Secrets Safe in Production
Kubernetes Secrets, on their own, are not enough for production. Base64 is not encryption, etcd does not encrypt by default, and anyone with read access to Secrets in a namespace can decode every value. A production setup needs more, and the layers below are the standard ones.
First, enable encryption at rest for Secrets in etcd. The API server supports an encryption configuration that encrypts Secret data before it is written to etcd, using a key stored on the control plane or in an external key management service. Managed Kubernetes services generally enable this by default or offer it as a setting; on a self-managed cluster you must configure it yourself. This is the single most important step, because without it, anyone who can read etcd or its backups can read every secret in the cluster.
Second, restrict RBAC. Give developers access to ConfigMaps but not Secrets, and give Secrets access only to the service accounts that need it and the operators who manage them. Audit who can read Secrets regularly, because permissions accumulate over time and the person who needed access for one incident three months ago still has it. The principle is least privilege: nobody should be able to read a secret they do not need for their current work.
Third, use an external secrets manager. Tools such as HashiCorp Vault, AWS Secrets Manager, Azure Key Vault and Google Secret Manager store secrets outside the cluster, with rotation, auditing and access control built in. The External Secrets Operator synchronises values from the manager into Kubernetes Secrets, so applications keep using the native Secret mechanism while the real storage lives in a system designed for secrets. The operator also handles rotation: when a password changes in the vault, the Kubernetes Secret is updated automatically.
Fourth, avoid putting secrets in environment variables where you can. Mount them as files instead, so they are not visible in process listings and are not inherited by child processes that do not need them. And never log a secret. Applications that log their environment on startup are leaking every secret they were given, and that log line will live in your log aggregator long after the pod is gone. Audit your application’s startup logs for secret values before you ship it.
Fifth, rotate secrets regularly. A password that has not changed in two years is a password that has had two years to leak. Rotation is easier when secrets come from a manager that supports it, and harder when they were created by hand with kubectl. If rotation is painful, that is a sign the secrets workflow needs fixing, not a reason to skip rotation.
Common Mistakes and How to Avoid Them
The most common mistake is putting a secret in a ConfigMap because it was convenient. A database password in a ConfigMap is readable by everyone who can read ConfigMaps, it is stored in plain text, and it is probably committed to Git. The fix is mechanical: move it to a Secret, restrict RBAC, and remove it from the repository history, remembering that removing a file from the current commit does not remove it from history. If a secret has ever been committed, rotate it. There is no way to un-leak a credential.
The second mistake is storing a Secret manifest in Git. The base64 values look protected, and they are not. Anyone with repository access can decode them. Use sealed secrets, external secrets, or generate the Secret at deploy time from a vault. If your GitOps pipeline needs a Secret to exist, the pipeline should create it from a secure source, not from a file in the repository.
The third mistake is assuming a ConfigMap change takes effect immediately. Mounted volumes update within about a minute, but the application usually does not re-read its files, and environment variables never update without a restart. After changing a ConfigMap or Secret, restart the pods with a rollout restart and verify the new value is in use. A change that was never applied is worse than no change at all, because it creates a false belief that the problem is fixed.
The fourth mistake is creating Secrets with --from-literal on a shared machine or in a script that logs its commands. The password ends up in shell history, in the terminal scrollback, and in any audit log that records commands. Use --from-file instead, or read the value from a prompt without echo. Small habits like this are what separate a secure workflow from a leaky one.
The fifth mistake is giving every pod access to every Secret in the namespace. A pod should only be able to read the secrets it needs, and the service account it runs as should only have the permissions it needs. Broad permissions feel harmless until a pod is compromised, at which point the attacker inherits every secret the pod could read. Scope permissions narrowly from the start, because narrowing them later is a migration project.
Frequently Asked Questions
Is a Kubernetes Secret encrypted? Not by default. Secret values are base64-encoded, which is an encoding, not encryption, and anyone who can read the Secret can decode it. Encryption at rest must be enabled explicitly on the API server, and for production you should also use an external secrets manager with rotation and auditing. Treat a Secret as a labelled container for sensitive data, not as a vault.
Can I use a ConfigMap for passwords? You can, but you should not. A ConfigMap stores values in plain text, is readable by anyone with ConfigMap access, and is safe to commit to Git, which means a password in a ConfigMap is likely to end up in a repository. Passwords, tokens and keys belong in Secrets, with RBAC restrictions and encryption at rest enabled.
How do I update a ConfigMap without downtime? Edit the ConfigMap, then run kubectl rollout restart on the Deployment so new pods pick up the change. Mounted volumes update automatically within about a minute, but most applications only read configuration at startup, so a restart is the reliable path. For zero-downtime updates, rely on the Deployment’s rolling update strategy, which replaces pods gradually.
What is the difference between env and envFrom? The env field injects one key at a time with an explicit name, so you control exactly which values the pod receives. envFrom injects every key in a ConfigMap or Secret at once, which is shorter but gives the pod everything in the object, including values it may not need. Prefer env for important values and reserve envFrom for objects whose entire contents the pod genuinely uses.
Should I use Secrets or an external secrets manager? Use both. Kubernetes Secrets are the mechanism applications consume, and an external manager such as Vault or a cloud secrets service is where the values live, with rotation and auditing. The External Secrets Operator bridges the two. For learning and small projects, native Secrets with encryption at rest and tight RBAC are enough. For production, an external manager is the standard.
Conclusion
ConfigMaps and Secrets look alike because they solve the same problem, getting configuration into a pod, for two different kinds of data. ConfigMaps hold the values that are safe to share: hosts, ports, flags and file-based configuration that belongs in version control. Secrets hold the values that must be protected: passwords, tokens and keys, with the understanding that base64 is not encryption and that real protection comes from encryption at rest, tight RBAC, an external secrets manager and regular rotation. Choose between them with one question: would publishing this value cause harm? If yes, it is a Secret. Keep that test in mind, restart pods after changing configuration, and never commit a secret to Git. If you want to go deeper into Kubernetes fundamentals, our Kubernetes tutorial for beginners covers pods, deployments and services from first principles, and our CKA certification guide for 2026 shows how ConfigMaps and Secrets appear in the exam, which runs on Kubernetes v1.37 with a two-hour limit, 15 to 20 tasks and a 66 percent pass mark.
Sources: Verified 2 Dec 2026. Kubernetes ConfigMap documentation: https://kubernetes.io/docs/concepts/configuration/configmap/ ; Kubernetes Secret documentation: https://kubernetes.io/docs/concepts/configuration/secret/ . Kubernetes v1.37 current; 1.38 planned ~16 Dec 2026. CKA format (2 hours, 15–20 tasks, 66%, v1.37) cross-checked against Linux Foundation summaries. No unverified figures stated.



