Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Secrets

Direct answer

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.

When to use this

Use it to provide credentials to pods securely, or when a secret is missing or exposed.

First 30 seconds

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.

Operational verification

secret stored (encrypted at rest) → RBAC → mounted into pod

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it to provide credentials to pods securely, or when a secret is missing or exposed.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

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.

Key checks
  • kubectl get secret <s> -n <ns> — first check for this topic
  • kubectl get pods -o wide — pods, status, node, IP
  • kubectl describe pod <pod> — events and conditions
  • kubectl 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/watch on secrets; list reveals 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:

ControlProtects againstHow
Encryption at restReading etcd files or backupsEncryptionConfiguration with a KMS v2 provider (or aescbc/secretbox)
RBACUsers and service accounts reading secretsNarrow get on named secrets; list/watch reveal every value too
Pod accessWho can mount itAnyone who can create Pods in the namespace can mount any Secret there
DeliveryExposure in the containerPrefer 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Terminology layer

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.

Aliases that resolve here
secretskubernetes secretsencryption at rest secrets
Confirmation

Confirm action

Continue?