Sub topic 15
External secret managers
This chapter assumes you can create Secrets, mount them in Pods, and read basic RBAC rules. It covers why teams move secret storage outside the cluster and the common ways to bring those secrets back in.
Why look beyond native Secrets
A native Secret lives in etcd, the cluster's data store. Base64 is not encryption, so protection depends on RBAC and encryption at rest. Even with both in place, some gaps remain:
- Secret values are usually committed to Git as manifests, or pasted into
kubectlcommands, before they reach the cluster. - Rotation is manual. Someone must update the Secret and restart the Pods.
- Audit trails and access policies are limited to what Kubernetes offers.
- Several clusters need the same value, so you end up with several copies.
An external secret manager is a service built for this job. Examples are AWS Secrets Manager, HashiCorp Vault, Google Secret Manager, and Azure Key Vault. It stores the value, controls access by identity, logs every read, and supports rotation.
Two integration patterns
Most tools fall into one of two patterns.
| Pattern | How it works | Example tools | Trade-off |
|---|---|---|---|
| Sync to a Secret | A controller reads the external value and writes a normal Kubernetes Secret. | External Secrets Operator | Pods need no changes, but the value is again stored in etcd. |
| Mount directly | A CSI driver fetches the value when the Pod starts and mounts it as a file. | Secrets Store CSI Driver | The value can stay out of etcd, but the application must read files. |
A third option is an agent or sidecar that runs next to your application and fetches secrets itself. Vault Agent is one example.
Example: syncing with External Secrets Operator
The Operator is installed separately. You first define a SecretStore that tells it how to reach the provider. An ExternalSecret then names the remote value and the Secret to create. The SecretStore below assumes an AWS account with credentials already configured for the Operator.
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: db-credentials
spec:
refreshInterval: 1h
secretStoreRef:
name: aws-store
kind: SecretStore
target:
name: db-credentials
data:
- secretKey: password
remoteRef:
key: prod/db
property: passwordThe Operator creates a Secret named db-credentials and refreshes it every hour. Your Pods consume it with the same secretKeyRef or volume syntax you already know. Remember the update rules from earlier. A refreshed Secret reaches mounted files, but environment variables change only when the Pod restarts.
Common errors
- The synced Secret never appears. Run
kubectl describe externalsecret db-credentials. The status usually shows an authentication or missing-key error from the provider. - Wrong identity. The Operator or driver needs its own permission to read the remote value. Grant it the narrowest policy that works.
- Assuming the problem is solved. Synced Secrets still sit in etcd and still need RBAC and encryption at rest.
- Provider outage. A CSI mount can fail at Pod start if the manager is unreachable, so the Pod stays in
ContainerCreating.
Exercise
A team uses External Secrets Operator to sync a database password into a Secret. Their Pod reads it through an environment variable. The password is rotated in the external manager and the Operator refreshes the Secret. Why does the Pod still use the old password, and what are two ways to fix it?
Show answer
Environment variables are set when the container starts and are never updated in a running Pod. Fix it by restarting the Pods, for example with kubectl rollout restart deployment/<name>. Alternatively, mount the Secret as a volume and make the application re-read the file, because mounted files do pick up refreshed Secrets.