A Kubernetes custom controller that automatically releases retained static PersistentVolumes when a new PersistentVolumeClaim fails to bind due to an existing claimRef.
In Kubernetes clusters using static / manually managed PersistentVolumes, it is common to hit the following situation:
-
A PVC is deleted and later recreated
-
The underlying static PV uses:
persistentVolumeReclaimPolicy: Retain
-
The static PV transitions to Released
-
A new PVC tries to bind but fails with:
volume already bound to a different claim
This leaves the PVC stuck in Pending, requiring manual static PV editing.
static-pv-releaser automatically resolves this situation by:
- Watching PVC Create and Update events only
- Detecting PVCs stuck in Pending due to a bind conflict
- Finding PVs that:
- Have persistentVolumeReclaimPolicy: Retain
- Are in Released phase
- Are still bound to a different PVC
- Clearing the stale fields:
spec: claimRef: name: foo-pvc namespace: foo uid: "" resourceVersion: ""
- Letting Kubernetes re-bind the static PV to the new PVC