Use it to provide credentials to pods securely, or when a secret is missing or exposed.
Secrets
Secrets hold sensitive data (passwords, tokens, keys) base64-encoded, delivered as files or env vars; protected by RBAC and optional encryption at rest or external secret stores.
1. kubectl get secret <s> -n <ns> — exists, type?
2. Pod references the right keys?
3. RBAC: who can read secrets? kubectl auth can-i get secrets --as <sa>.
4. Encryption at rest configured?
5. Rotate and restart consumers.
secret stored (encrypted at rest) → RBAC → mounted into pod
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Confirm only the workload's service account can read the Secret. Rotate by updating the Secret and restarting or reloading the workload. Check that secrets are not printed in application logs.
Step 2 Common failures Narrow the fault
Committing Secret manifests to Git exposes the base64 value. Broad RBAC (get secrets in all namespaces) gives many users every credential. Environment variables keep the old value until the Pod restarts.
Base64 is not encryption — enable encryption at rest and restrict get secret via RBAC. Prefer mounted files over env vars. Consider External Secrets/CSI secret stores.
kubectl get secret <s> -n <ns>— first check for this topickubectl get pods -o wide— pods, status, node, IPkubectl describe pod <pod>— events and conditionskubectl logs <pod> [-c <c>] [--previous]— container logs (incl. previous crash)kubectl get events --sort-by=.lastTimestamp— recent cluster events
ReferenceWhat it is1 section · depth on demand
How it works
Secrets are stored in etcd like other objects. With an encryption configuration, the API server encrypts them before writing. The kubelet keeps mounted secrets in tmpfs on the node. External secret operators can sync values from a vault into Secrets.
ReferenceImportant terms & boundaries3 sections · depth on demand
Protecting Secrets
- Base64 is encoding, not encryption: enable encryption at rest for etcd (
EncryptionConfiguration, KMS provider). - RBAC: restrict
get/list/watchon secrets;listreveals all values. - Mount as files rather than env vars (env vars leak into logs and crash dumps).
- Use external secret stores (External Secrets Operator, Vault, CSI Secrets Store) and rotate.
kubectl create secret generic db --from-literal=password=<value>
In depth
A Secret's data values are base64-encoded so they can carry binary content; that is not protection. Protection comes from four separate controls:
| Control | Protects against | How |
|---|---|---|
| Encryption at rest | Reading etcd files or backups | EncryptionConfiguration with a KMS v2 provider (or aescbc/secretbox) |
| RBAC | Users and service accounts reading secrets | Narrow get on named secrets; list/watch reveal every value too |
| Pod access | Who can mount it | Anyone who can create Pods in the namespace can mount any Secret there |
| Delivery | Exposure in the container | Prefer volume mounts (tmpfs) over env vars, which leak into crash dumps and child processes |
Verify encryption at rest is actually applied
ETCDCTL_API=3 etcdctl get /registry/secrets/app/db-pass | hexdump -C | head -3
# k8s:enc:kms:v2:… → encrypted plain JSON/protobuf → not encrypted
kubectl get secrets -A -o json | kubectl replace -f - # re-write existing secrets after enabling
Secrets created before encryption was enabled stay unencrypted until they are written again.
External secret stores
Tools such as External Secrets Operator or the Secrets Store CSI driver pull values from Vault or a cloud secret manager. They improve rotation and audit, but a synced Kubernetes Secret is still subject to the controls above.
Rotation
Update the Secret, then restart or signal the workload. Mounted files refresh after kubelet sync (not with subPath); environment variables never refresh.
Common mistakes
- Treating base64 Secrets as encrypted (enable encryption at rest).
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.