Kubernetes Secret is a Kubernetes API object used to store sensitive data such as passwords, API tokens, TLS certificates, SSH keys, and registry credentials. In practical terms, it lets your pods consume sensitive values without hardcoding them into container images, application code, or plain deployment manifests.
A Secret separates sensitive configuration from your workload definition. Instead of putting a database password directly in a Deployment, you create a Secret and reference it from the pod.
Applications usually consume Secrets in one of two ways:
DATABASE_PASSWORD./etc/secrets/api-key or /etc/tls/tls.crt.This keeps sensitive values outside the container image and makes it easier to rotate credentials without rebuilding the application.
A Secret is stored in the Kubernetes API server and persisted in the cluster backing store, usually etcd. Secret values are base64-encoded in the object definition, but base64 is encoding, not encryption.
A simplified Secret looks like this:
apiVersion: v1
kind: Secret
metadata:
name: app-database-secret
type: Opaque
data:
username: YXBwdXNlcg==
password: c3VwZXItc2VjcmV0
A pod can then reference the Secret:
env:
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: app-database-secret
key: password
When the pod starts, Kubernetes makes the selected Secret value available to the container. If the Secret is mounted as a volume, Kubernetes can update the mounted file after the Secret changes. If the Secret is used as an environment variable, the pod usually needs a restart to pick up the new value.
Kubernetes supports several Secret types. The type helps Kubernetes and tools understand what the Secret contains.
tls.crt and tls.key.A Secret and a ConfigMap are both Kubernetes API objects used to separate configuration from application code, but they serve different purposes.
The distinction matters for access control, auditing, and operational habits. Engineers should treat Secrets with stricter permissions and avoid storing them in plain text Git repositories.
Kubernetes Secrets are useful, but they are not a complete secrets management system by themselves.
If you manage Kubernetes manifests with infrastructure as code, be careful not to place real secret values directly in state files or repositories. For example, when you deploy Kubernetes resources using Terraform, you should account for where sensitive values are stored, who can read the state, and how rotation will work.
Suppose you run a Node.js API in Kubernetes and it needs to connect to PostgreSQL. You can store the database password in a Secret named api-db-secret. Your Deployment references that Secret as an environment variable called DATABASE_PASSWORD.
The container image stays the same across development, staging, and production. Each environment gets its own Secret value. If the production password changes, you update the Secret and restart the affected pods instead of rebuilding the image.
Many teams use Kubernetes Secrets as the final delivery mechanism to pods, while storing the source of truth in a dedicated secrets system such as AWS Secrets Manager, HashiCorp Vault, Google Secret Manager, or Azure Key Vault.
In that setup, an operator or controller syncs external secret values into Kubernetes Secrets. This pattern works well when teams need centralized rotation, audit logs, and cloud IAM integration. It is also common in clusters that manage cloud resources through Kubernetes APIs, such as when teams deploy AWS resources using Crossplane on Kubernetes.
A Kubernetes Secret is best understood as a Kubernetes-native way to pass sensitive values to workloads. It improves separation of concerns, but you still need strong access control, encryption at rest, safe deployment workflows, and a clear rotation strategy.