Video in progress
What is the difference between a ConfigMap and a Secret, and is a Secret really encrypted?
A ConfigMap is for ordinary settings, a Secret is for passwords and keys. But by default the value in a Secret is only base64-encoded, which is not encryption: anyone can read it with base64 -d.
📖 Answer
kubectl get secret db-creds -o jsonpath='{.data.password}' | base64 -d
# S3cr3t! <- and that's all it takes
Technically the difference between a Secret and a ConfigMap is small, and it is mostly about intent:
- RBAC can restrict reading Secrets separately;
- the kubelet mounts them into memory (tmpfs) on the node, not onto disk;
- encryption in etcd (encryption at rest) has to be turned on separately by the cluster admin, and it is off by default.
Wiring them into the app:
env:
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef: { name: db-creds, key: password }
envFrom:
- configMapRef: { name: shop-api-config }
A practical trap: committing the Secret YAML to git. Base64 hides nothing. That is why solutions such as Sealed Secrets, SOPS or the External Secrets Operator (which pulls from Vault or a cloud secret manager) are used.
Sign up to mark studied questions and save your progress.