How do Kubernetes Secrets work, and are they secure?

IntermediateConceptDatabase connections in apps
Answer

Short answer

A Secret is a Kubernetes object that holds sensitive values (passwords, tokens, certificates) and makes them available to pods as environment variables or mounted files. By default the values are only base64-encoded, not encrypted, so security depends on enabling encryption at rest in etcd, strict RBAC, and ideally sourcing them from an external secret manager.

Example

kubectl create secret generic orders-db \
  --from-literal=username=orders_app \
  --from-literal=password='S3cret!'
env:
  - name: DB_PASSWORD
    valueFrom:
      secretKeyRef: { name: orders-db, key: password }
# or as files:
volumeMounts: [{ name: db, mountPath: /etc/secrets, readOnly: true }]
volumes: [{ name: db, secret: { secretName: orders-db } }]

Base64 is not encryption

kubectl get secret orders-db -o jsonpath='{.data.password}' | base64 -d   # S3cret!

Making them safer

  1. Encryption at rest for etcd (managed clusters like EKS/AKS support KMS encryption).
  2. RBAC — only specific service accounts can get secrets in a namespace.
  3. Don't commit Secret YAML to Git — use External Secrets Operator, Sealed Secrets or SOPS.
  4. Prefer mounted files for very sensitive values (env vars can leak via crash dumps or /proc).

What to say in the interview

"Secrets are base64-encoded objects exposed as env vars or files. They're only as secure as etcd encryption and RBAC, so we enable KMS encryption, restrict access, and populate them from Vault or a cloud secret manager via External Secrets rather than storing YAML in Git."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Connecting apps to databases

More on Database connections in apps