liveBook · Manning

Kubernetes Secret

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A Secret is a Kubernetes API object intended to hold sensitive data such as credentials or tokens.

A Kubernetes Secret is an API object for sensitive data such as credentials, passwords, or certificate data. Values are base64-encoded, but stored unencrypted by default; anyone with cluster access may be able to read them, so a Secret should not be the only security control. section 4.2.5

Use a Secret as part of an observable administrator workflow:

  • Generate a manifest with kubectl: kubectl create secret generic dev-login --from-literal=username=dev --from-literal=password='S!B*d$zDsb=' --dry-run=client -o yaml > dev-login.yaml. section 4.2.5
  • Inspect the manifest to see base64-encoded values, then create or update the object with kubectl apply -f dev-login.yaml. section 4.2.5
  • Expose the Secret to a pod either by mounting it as a volume or by supplying its values through environment variables. section 4.2.5 section 4.3
  • Verify a volume mount with kubectl exec secret-pod -- cat /etc/secret-vol/username and the corresponding password command. section 4.2.5

Expose Secret data through a volume

Create a Secret named dev-login, add a Secret volume and volume mount to a busybox pod, then inspect /etc/secret-vol/username and /etc/secret-vol/password from inside the running container. The same data can be passed through environment variables when the pod command prints its environment. section 4.2.5

Figure 4.20 Mount the secret data for the pod to access, ensuring the data can be reached from /etc/secret-vol inside the container.
figure

Use the manifest illustration to connect the Secret volume declaration with the container path that exposes the data. section 4.2.5

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Explains creation, base64 encoding, volume mounts, environment variables, and verification while warning that default storage is unencrypted.
Examples
Uses a dev-login Secret, a busybox pod, mounted files, kubectl exec output, and environment-variable inspection.
What it assumes
Assumes basic kubectl and pod-manifest skills while reinforcing Secret creation and both pod injection methods for the exam.
What you can do after
Apply it via kubectl, attach it to a pod, and verify sensitive values through a volume mount or environment variable.
How it connects
Connects Secrets with ConfigMaps, pods, volume mounts, environment variables, and base64 encoding.

Also explained in

Compare how 6 books explain Kubernetes Secret →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.