A Secret has the same shape as a ConfigMap, with two differences: how the values are stored, and who is meant to read them.
Create and read
text
learner@shallows:~$ kubectl create secret generic db-creds --from-literal=password=s3cret
secret/db-creds created
learner@shallows:~$ kubectl get secret db-creds -o yaml
apiVersion: v1
data:
password: czNjcmV0
kind: Secret
type: OpaqueThe value is base64-encoded. That keeps binary data safe inside YAML. It is not a disguise:
text
learner@shallows:~$ kubectl get secret db-creds -o jsonpath='{.data.password}' | base64 -d
s3crets3cret
base64base64 -d
czNjcmV0
In a manifest you may write stringData: with plain values; the API server encodes them into data: for you.
Types
| Type | Made with | Holds |
|---|---|---|
Opaque | create secret generic | Any keys and values |
kubernetes.io/tls | create secret tls | tls.crt and tls.key |
kubernetes.io/dockerconfigjson | create secret docker-registry | Credentials for pulling private images |
What makes it secret
Not the encoding. Three things do:
- Access: Chapter 10 shows how to let a role read ConfigMaps but not Secrets.
- Handling:
describe secrethides the values; dashboards do too. - Encryption at rest: a cluster can be set to encrypt Secrets in etcd. ConfigMaps never are.