Skip to content
tezvyn:

Compare Kubernetes Secrets versus environment variables for Pod credentials

Source: kubernetes.ioHardHow cards are made

Compare Kubernetes Secrets versus environment variables for Pod credentials

Tests Kubernetes credential threat model across etcd and Git. Plain env vars leak into manifests and process lists; Secrets enable RBAC but are base64 by default and visible to nodes and authorized readers. Red flag: claiming Secrets are encrypted by default.

What's really being asked

This question probes your ability to reason about defense in depth inside a cluster. The interviewer wants to see that you understand the difference between configuration management and secrets management, and that you can trace a credential from the developer laptop through version control, the API server, etcd, the kubelet, and finally the container runtime and process table. They are looking for awareness of RBAC, node compromise, etcd encryption, and the practical reality that Kubernetes Secrets are a distribution mechanism rather than a vault.

The full answer

First, plain environment variables defined directly in a Deployment manifest mean the secret is stored in version control, visible to anyone with manifest read access, and embedded in the container process environment where it can be leaked via ps, proc, or debug sidecars. Second, Kubernetes Secrets decouple the credential from the workload manifest, allowing independent RBAC, rotation, and admission control, but they are stored in etcd as base64 by default and are readable by the kubelet and any identity with Secret get or list in that namespace. Third, the node threat model matters because if an attacker gains root on the worker node, they can read Secrets from the local kubelet cache or filesystem unless additional protections like encryption at rest or external secret stores are used. Fourth, best practices such as mounting Secrets as volumes rather than environment variables to reduce exposure in process listings, enabling etcd encryption providers, using external secret management systems like Vault or cloud KMS integrations, and restricting Secret access via RBAC and network policies.

The mistakes people make

A major red flag is claiming that Kubernetes Secrets are encrypted by default or that the name Secret implies security. Another is saying environment variables are fine for production because the cluster is private or behind a firewall. Some candidates also miss the node-level exposure entirely and focus only on the API server. Failing to mention that base64 is encoding rather than encryption signals shallow knowledge. Finally, suggesting that Git history is not a concern because the repo is private shows poor secrets hygiene.

What usually comes next

The interviewer may ask how you would rotate a database password without restarting pods, how you would handle secrets in a multi-tenant cluster, or what happens to a Secret when it is updated while mounted as a volume. They might also ask for a comparison with external secret operators or how to encrypt etcd at rest.

A concrete example

Imagine a Deployment that sets DB_PASSWORD directly in the env block. A junior engineer commits this to Git. Even after removing it, the value persists in Git history. The value also appears in kubectl describe pod output for anyone with pod read access. In contrast, creating a Secret and referencing it with envFrom keeps the value out of the manifest, but the pod still exposes it via proc. A senior candidate would recommend mounting the Secret as a file under tmpfs, reading it at application startup, and enabling etcd encryption with a KMS provider so that the value is encrypted before hitting the underlying disk on the control plane node.

Interview question

A team moves a database password from a Deployment's env block into a Kubernetes Secret referenced via envFrom. Which statement accurately describes the remaining and mitigated risks?

  • a.The password is masked from kubectl describe output and removed from the node filesystem, though it can still be leaked via debug sidecars attached to the pod.
  • b.The password is protected from node compromise because RBAC on the Secret replaces the need for etcd encryption in a private cluster.
  • c.The password remains visible in the container's process environment, but it is decoupled from version control and still base64 in etcd readable by the kubelet and authorized identities.Correct
  • d.The password is no longer in Git history or pod manifests, but it is now encrypted at rest in etcd and invisible to the kubelet.
Why?

Moving the password into a Secret removes it from the manifest and version control, but because it is still referenced via envFrom it remains in the container's process environment; furthermore, Secrets are stored as base64 in etcd by default and are readable by the kubelet and any authorized identity in the namespace. Option D is tempting because it correctly notes the decoupling from Git but falls into the common misconception that Secrets are encrypted by default and invisible to nodes.

Just read this? Test yourself on what you have been reading.

Read the original → kubernetes.io

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.

See open roles