K8s by Example: Secrets
| Secrets store sensitive data: passwords, tokens, keys. Base64-encoded by default (not encrypted!). In production, enable encryption at rest and consider external secret managers like Vault or AWS Secrets Manager. |
| secret.yaml | |
| Secrets use the core | |
| secret-stringdata.yaml | |
| Use | |
| secret-types.yaml | |
| Secret types provide structure and validation. | |
| pod-secret-env.yaml | |
| Inject secrets as environment variables. Same pattern as ConfigMaps. Use | |
| pod-secret-volume.yaml | |
| Mount secrets as files. Files are stored in tmpfs (RAM, not disk). Set proper permissions with | |
| terminal | |
| Docker registry secrets authenticate image pulls from private registries. Create with kubectl or declaratively. | |
| Reference in Pod spec with | |
| encryption-config.yaml | |
| Encryption at rest protects Secrets in etcd. Without it, Secrets are only base64-encoded (easily decoded). Configure EncryptionConfiguration on the API server. | |
| terminal | |
| Best practices: use RBAC to restrict Secret access, avoid committing to Git (use sealed-secrets), rotate credentials regularly. Secrets are namespaced. | |