Module 5 ยท Lesson 5.2
Secrets
Mechanically, almost the same object
A Secret is consumed exactly like a ConfigMap โ env var via
secretKeyRef, envFrom, or a mounted volume. If you understood the last
lesson, you already know how to use one. The only real differences are in
what Kubernetes does with the data, and what you should assume about it.
base64 is not encryption
Open a Secret with kubectl get secret <name> -o yaml and the values are
base64-encoded strings, not the plain text you wrote. It is extremely
common to mistake this for security. It isn't: base64 is just an
encoding โ a reversible way to represent arbitrary bytes as plain text
(the same trick email attachments have used for decades), not a cipher.
Anyone who can read the Secret object through the API can decode it in one
command: echo '<value>' | base64 -d. No password, no key, nothing to
crack.
Linux aside: encodings like base64 translate data into a different representation with no secret involved โ reversible by anyone, by design. Encryption transforms data using a key, reversible only by whoever holds that key. Confusing the two is one of the most common security misunderstandings in infrastructure work generally, not just Kubernetes.
What actually protects a Secret
Real protection comes from layers outside the Secret's own encoding:
- RBAC restricting who can
get/listSecret objects at all โ the thing actually worth getting right (Module 11). - Encryption at rest for etcd itself, so a stolen disk doesn't hand over every Secret in the cluster โ a cluster-operator-level setting, not something you configure per-Secret.
- In real production, often an external secret store (AWS Secrets Manager, Vault) with Kubernetes only holding a short-lived reference โ exactly what Module 15 touches on for EKS.
None of that is "turn on a flag on the Secret" โ it's about everything around the Secret.
The infrastructure analogy
Treat a Kubernetes Secret the way you'd treat a value sitting in a shared password vault with weak access controls: fine for convenience, not a substitute for actually restricting who's allowed to open the vault. The object type's name is aspirational, not a guarantee.
In the lab, you'll wire a Secret into a Pod and fix a realistic typo โ a Secret key name that doesn't match what the Pod expects โ the same failure mode as the ConfigMap lab, just one object type over.
๐งช Lab: lab-10-secrets
Preview onlyGoal
Wire a Secret into a Deployment, see for yourself that it's just encoded (not encrypted), and fix the same kind of key-mismatch bug as the ConfigMap lab โ one object type over.
Tasks
- Apply the starting manifests:
kubectl apply -f manifests/ - Look at the live Secret:
kubectl get secret db-creds -n lab-10-secrets -o yaml. The value isn't the plain text you wrote inmanifests/secret.yamlโ decode it yourself:echo '<the base64 value>' | base64 -d. No password, no key, just text transformed back and forth. - Check the pod:
kubectl get pods -n lab-10-secrets. NotRunningโ sameCreateContainerConfigErrorfailure mode as the ConfigMap lab. kubectl describe pod -n lab-10-secrets -l app=appโ read the Events.- Fix it: edit
manifests/deployment.yamlsosecretKeyRef.keymatches a key that actually exists in the Secret, thenkubectl apply -f manifests/deployment.yamlagain. - Confirm:
kubectl exec -n lab-10-secrets deploy/app -- printenv DB_PASSWORDprints the Secret's value.
Check
Run the check once the pod is Running and DB_PASSWORD resolves
correctly inside the container.
This lab runs against a real local Kubernetes cluster with an automated grader โ clone the repo and run make start to do it for real.
๐ Quiz
1. You run `kubectl get secret db-creds -o yaml` and see base64 text instead of your original password. What does that base64 encoding actually provide?scenario
2. What's the real difference between a ConfigMap and a Secret from the Pod's point of view?
3. Which of these actually improve Secret security? (select all that apply)
4. A Pod references secretKeyRef with key 'password', but the Secret's actual key is 'db_password'. What happens?scenario
5. Where does Module 11 (RBAC) connect back to this lesson?
Progress isn't saved in this preview โ run the course locally to track completion and grade labs for real.