Summary - Secret
- Docker & Kubernetes course
- Intermediate
- Lesson 54/82
- 5 min
Combine YAML and mount to use sensitive data safely.
Summary: Secrets
In this group:
- A Secret holds secret data; values are base64, not encrypted. They aren't put in Git and are protected with RBAC and etcd encryption.
- Types:
Opaque,kubernetes.io/tls,dockerconfigjson(imagePullSecrets). - In YAML,
stringDataaccepts plain text;echo -nprevents the trailing newline. - Usage:
secretKeyRef/secretRefor asecret.secretNamevolume (defaultMode). - Rotation:
--dry-run=client -o yaml | kubectl apply -f -androllout restart.
kubectl create secret generic db-gizli --from-file=DB_PASSWORD=./parola.txt
kubectl get secret db-gizli -o jsonpath='{.data.DB_PASSWORD}' | base64 -dPractice Mount the TLS secret
Write a pod's spec section (starting with spec:): a tls volume from the web-tls Secret with defaultMode: 0400 under volumes; container named nginx, image nginx:1.27; mount tls at /etc/tls with readOnly: true.
Starter code
# buraya yazSample solution
spec:
volumes:
- name: tls
secret:
secretName: web-tls
defaultMode: 0400
containers:
- name: nginx
image: nginx:1.27
volumeMounts:
- name: tls
mountPath: /etc/tls
readOnly: trueExpected output
pod/web configured $ kubectl exec web -- ls /etc/tls tls.crt tls.key
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is used to keep a Secret YAML safely in a Git repository?
- Writing type: Opaque
- A tool like Sealed Secrets or External Secrets Correct answer
- Encoding with base64 once more
- Using stringData
Explanation: Sealed Secrets produces an encrypted object that only the cluster can decrypt.
2 Mount the Secret as a volume.
volumes:
- name: tls
secret:
____: web-tls
volumes:
- name: tls
secret:
secretName: web-tls
Explanation: A Secret volume uses secretName.
3 Match.
| Term | Meaning |
|---|---|
Secret |
Secret |
ConfigMap |
Not secret |
base64 -d |
Decode the value |
imagePullSecrets |
Private registry |