Welcome to the HashiCorp Vault series! In this lesson, we’ll review how Kubernetes stores sensitive data in Secrets, highlight key drawbacks, and prepare for a secure injection of dynamic secrets using Vault.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Why Use Kubernetes Secrets?
Managing sensitive data—passwords, API tokens, SSH keys—is critical in any deployment. Kubernetes Secrets help you:- Decouple credentials from application pods and container images
- Store sensitive values centrally in etcd (the Kubernetes key-value store)
- Consume secrets as mounted volumes or environment variables
| Mount Method | Use Case | Example |
|---|---|---|
| Volume mount | Inject files (e.g., TLS certs) | volumes: - name: creds |
| Environment var | Pass small values (e.g., DB password) | env: - name: DB_PASS |
Kubernetes Secrets are only base64-encoded, not encrypted by default. Any user with API or etcd access can decode them.
Creating a Generic Secret
Create a simple Secret in one command:Viewing Secrets Directly in etcd
With etcd client certificates, stored Secrets appear in plain text:Mitigation: Encryption at Rest
Kubernetes supports encrypting Secrets in etcd with anEncryptionConfiguration.
-
Create
/etc/kubernetes/pki/encryption-config.yaml: -
Update the API server flags:
- Restart the kube-apiserver. All new Secrets will be encrypted in etcd.
To encrypt existing Secrets, run:
Best Practices for Kubernetes Secrets
| Best Practice | Description |
|---|---|
| Restrict etcd access | Limit etcdctl and API access to cluster administrators only. |
| Enforce TLS | Enable TLS for all component communications. |
| Audit logging | Turn on audit logs for kubectl and API server operations. |
| Use an external secret store | Integrate HashiCorp Vault for dynamic, auditable secrets. |