Kubernetes Secrets (Opaque, docker-registry, tls)
Store credentials and TLS material in Secret types consumed by pods and controllers.
In plain words
A Secret type is a labeled envelope with an expected form, not a safe or a guarantee that the letter is encrypted inside the mailroom. The simple Kubernetes rule is: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
Think of it like…
A Secret type is a labeled envelope with an expected form, not a safe or a guarantee that the letter is encrypted inside the mailroom.
Where you’ve seen it
A platform team reviews a promoted source revision and runs kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem. Expected evidence: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress. If the run instead shows this symptom, stop and restore the last known state: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data.
Words you’ll hear
- Opaque
- For this lesson, Opaque is the controlling idea: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
- docker-registry
- docker-registry is the checkpoint; run
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pemand inspect the owner chain. Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data. - tls
- tls is the outcome to preserve; the cost is explicit: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected.
- Verification evidence
- The evidence command is
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem. It connects the declaration to this behavior: Store credentials and TLS material in Secret types consumed by pods and controllers.
Visual diagram
Theory & deep dive
How Opaque reaches the intended state
Store credentials and TLS material in Secret types consumed by pods and controllers. Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
The concrete checkpoint is kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem; compare the Opaque owner, docker-registry state, and tls outcome instead of treating YAML acceptance as proof.
Run kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem after the change and correlate the result with Events and the owning object. Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
docker-registry: failure boundary and production cost
Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data. The prerequisite contract is concrete: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected. A safe design limits blast radius, records the last good configuration, and uses kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem as a deterministic rollback checkpoint.
Capture the current state with kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data.
How it works, step by step
Step 1 of 41. Choose the source of truth
Version the source and describe the review, render, and reconciliation boundary: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
- Goal
- Store credentials and TLS material in Secret types consumed by pods and controllers.
- Owner
- Opaque
When to use it & trade-offs
What it is
Store credentials and TLS material in Secret types consumed by pods and controllers. Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
Why it matters: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data. The invariant at risk is specific: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress. The quickest fact check before changing the design is kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem.
When to reach for it
- Use Opaque to enforce this invariant: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
- Use docker-registry evidence from
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pemin reviews and incident timelines. Store credentials and TLS material in Secret types consumed by pods and controllers. - Choose the platform operator workflow route only when this cost is justified by governance or scale: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected.
When to avoid or be careful
- Avoid assuming Opaque is complete after YAML submission; the required behavior is concrete: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
- Avoid treating the next symptom as random; check the owner and state with
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pemfirst: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data. - Avoid adopting a heavier platform wrapper before measuring its cost: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected.
Native, manual, and managed paths for Opaque
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem.Strengths: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
Watch out: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected. Recovery must also recognize this signal: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data.
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem; the expected invariant is: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.Strengths: kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike Opaque, it does not make this symptom self-documenting: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data.
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
Watch out: The added platform ownership buys value at this cost: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
- Trace Opaque to tls through docker-registry; the invariant is: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
- Recognize the symptom: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data.
- Justify the cost: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected.
- Verify with kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem instead of only inspecting YAML.
Benchmarks & rules of thumb
- 3
- common types in this lesson: Opaque, docker-registry, and tls
- 2
- required TLS data keys in a typed Secret
- 0
- base64-based confidentiality
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the Opaque owner contract: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress.
- Ignoring this telltale condition leads to unrelated changes: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data.
- Repeating
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pemwithout an owner for remediation wastes retry cost. Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress?
- Which owner object, logs, and Events would you inspect for this symptom-Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data-?
- At what threshold would this cost become unacceptable: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected?
kubectl create secret generic api-token --from-literal=token=$TOKEN; kubectl create secret tls app-tls --cert=cert.pem --key=key.pem, name the failure, then justify the cost. Invariant: Opaque Secrets accept arbitrary key/value data, docker-registry Secrets hold registry credentials, and tls Secrets conventionally contain tls.crt and tls.key for controllers and Ingress. Failure: Secret type is descriptive rather than encryption, so wrong content keys, overly broad RBAC, and environment dumps can expose the same credential data. Cost: Native Secret types simplify consumers, but lifecycle ownership, encryption at rest, rotation, and audit policy determine whether credentials are actually protected.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Kubernetes Secrets (Opaque, docker-registry, tls) with generative AI interview Q&A and hands-on practice.