Secret
In one line
A Secret is a Kubernetes resource that stores sensitive data such as passwords, tokens, and keys, encoded in base64.
In simple words
A Secret is like a ConfigMap but for sensitive data — passwords, API keys, TLS certificates, database credentials. The values are stored base64-encoded, which is not encryption but prevents casual viewing.
Secrets can be mounted as files or injected as environment variables into your Pods. For real security, you should combine Secrets with encryption at rest (enabled in the cluster) and use tools like HashiCorp Vault or cloud KMS for production-grade secret management.
There are several types of Secrets: Opaque (generic key-value), kubernetes.io/tls (TLS certificate + key), and kubernetes.io/dockerconfigjson (registry credentials).
Example
apiVersion: v1
kind: Secret
metadata:
name: db-credentials
type: Opaque
data:
username: YWRtaW4= # base64 of 'admin'
password: c2VjcmV0 # base64 of 'secret'This Secret stores a database username and password, base64-encoded. The Pod can use them as environment variables.
How it works
- You create a Secret with base64-encoded sensitive data.
- You reference it in your Pod spec as env vars or a mounted volume.
- The container decodes and uses the values at runtime.
- Enable encryption at rest in the cluster for real protection.
Common confusions
Confused with: ConfigMap
The difference: Secrets store sensitive data base64-encoded and have access controls; ConfigMaps store non-sensitive data in plain text.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.