Sub topic 10
Controlling ownership and deletion of the target Secret
This chapter assumes you know Kubernetes owner references and garbage collection, and that you can already write an ExternalSecret. It covers two fields on the ExternalSecret that decide who owns the target Secret and what happens to it when something disappears.
Two different events
Two events can remove or change the target Secret, and a separate field controls each one:
spec.target.creationPolicycontrols how the Secret relates to the ExternalSecret. It decides whether ESO creates the Secret and whether deleting the ExternalSecret deletes the Secret.spec.target.deletionPolicycontrols what ESO does when the provider reports that the remote secret no longer exists.
creationPolicy
| Value | Behaviour |
|---|---|
| `Owner` (default) | ESO creates the Secret and sets an owner reference to the ExternalSecret. Deleting the ExternalSecret garbage-collects the Secret. |
| `Orphan` | ESO creates the Secret without an owner reference. The Secret survives deletion of the ExternalSecret. |
| `Merge` | ESO does not create the Secret. It writes keys into a Secret that already exists, without owning it. |
| `None` | ESO neither creates nor updates the Secret. |
Owner suits most workloads because cleanup is automatic. Orphan suits cases where Pods must keep running while you rework or recreate the ExternalSecret. Merge suits a Secret created by another tool, such as a Helm chart, to which you want to add a few synced keys.
deletionPolicy
| Value | Behaviour when the remote secret is gone |
|---|---|
| `Retain` (default) | The Secret stays, with its last synced values. |
| `Delete` | ESO deletes the Secret. |
| `Merge` | ESO removes only the keys it wrote and leaves the rest of the Secret in place. |
Retain is the safe default. A deleted or renamed remote secret does not take down running Pods. The risk is that the cluster keeps serving a value that was revoked at the source. Use Delete when a revoked secret must stop working in the cluster.
Example
This ExternalSecret creates an unowned Secret and removes it if the remote secret is deleted:
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: db-credentials
namespace: app
spec:
refreshInterval: 1h
secretStoreRef:
name: aws-store
kind: SecretStore
target:
name: db-credentials
creationPolicy: Orphan
deletionPolicy: Delete
data:
- secretKey: password
remoteRef:
key: prod/db
property: passwordHere Orphan and Delete pull in opposite directions. The Secret outlives the ExternalSecret, but it still disappears if the provider says the remote value is gone. Choose each field on its own merits.
Checking ownership
Inspect the owner reference to see which policy is in effect:
kubectl get secret db-credentials -n app \
-o jsonpath='{.metadata.ownerReferences[*].kind}'With Owner, the output is ExternalSecret. With Orphan or Merge, the output is empty.
Exercise
A team deletes an ExternalSecret that uses the default policies, and their Pods lose access to the Secret on the next restart. Which field would have prevented this, and what value would you set?
Show answer
Set spec.target.creationPolicy: Orphan. The default Owner adds an owner reference, so deleting the ExternalSecret garbage-collects the Secret. With Orphan there is no owner reference, so the Secret remains.