Sub topic 9
Refresh intervals and rotation
This chapter assumes you can write an ExternalSecret and have one syncing from a SecretStore. It covers how often ESO re-reads the remote value and how a rotated value reaches your application.
How a refresh works
An ExternalSecret is not copied once. The ESO controller reconciles it on a timer. Each time the timer fires, the controller:
- Reads the remote value from the provider.
- Builds the target Secret from it.
- Updates the Kubernetes Secret only if the data changed.
The timer is set by spec.refreshInterval. If you omit it, the default is 1h.
Setting the interval
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db-credentials
namespace: app
spec:
refreshInterval: 15m
secretStoreRef:
name: aws-store
kind: SecretStore
target:
name: db-credentials
data:
- secretKey: password
remoteRef:
key: prod/db
property: passwordThe value is a Go duration such as 30s, 15m or 1h. Setting refreshInterval: "0s" disables periodic refresh, so the Secret is created once and then left alone. Changing the ExternalSecret spec still triggers a reconcile.
Pick the interval by weighing two costs:
| Shorter interval | Longer interval |
|---|---|
| Rotated values arrive sooner | Fewer provider API calls |
| More calls, which may be billed or rate limited | A rotated value stays stale longer |
Every ExternalSecret makes its own calls. Hundreds of ExternalSecrets on a 10-second interval can hit provider quotas, so choose the longest interval your rotation policy allows.
Forcing a sync
To refresh now, change an annotation on the ExternalSecret. Any change to the object triggers a reconcile.
kubectl annotate externalsecret db-credentials -n app \
force-sync="$(date +%s)" --overwrite
kubectl get externalsecret db-credentials -n appThe READY column should show True with reason SecretSynced. kubectl describe also shows Refresh Time, the last successful sync.
From Secret to running process
Updating the Kubernetes Secret is not enough. How the Pod consumes it decides whether the new value is picked up.
- Environment variables are read once when the container starts. A rotated value appears only after the Pod restarts.
- Mounted volumes are refreshed by the kubelet, usually within a minute or two. The application must re-read the file.
- Volumes mounted with
subPathare never updated. AvoidsubPathfor rotating secrets.
For apps that cannot reload files, restart them after rotation. Tools such as Reloader watch Secrets and roll the Deployment for you.
Total delay is roughly the provider rotation time, plus up to one refreshInterval, plus the kubelet delay, plus the time the app takes to re-read. Plan for the sum, not just the interval.
Common mistakes
- Expecting env variables to change in a running Pod.
- Setting
0sand then wondering why a rotation never arrived. - Using a very short interval across many ExternalSecrets and exhausting provider API limits.
- Rotating the credential at the provider before consumers have the new value. Where possible, use a rotation scheme where the old and new values are both valid for a short overlap.
Exercise
The remote secret prod/db rotates at 10:00. The ExternalSecret has refreshInterval 1h, and the Pod reads the password through an environment variable. A teammate says the app will use the new password by 11:05. Why might that be wrong, and what would you change?
Show answer
There are two problems. The Kubernetes Secret may not update until up to an hour after 10:00, because the controller only reads on its timer. Even after it updates, the environment variable is fixed at container start, so the running app keeps the old password until the Pod restarts. To fix it, force a sync or shorten the interval, and restart the Pods after the Secret changes, for example with a reloader tool. Or mount the Secret as a volume and have the app re-read the file.