From 326d39de8ad5d55a9af0e94c40c94cd368d197ec Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Mon, 13 Nov 2023 23:29:02 +0200 Subject: [PATCH] Delete PVCs when stateful set is deleted Add PVC retention policy[1] to delete the PVCs when the statesfulset is deleted. Retain PVCs when scaling down so we can scale up again without loosing data. [1] https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention Signed-off-by: Nir Soffer --- busybox-statefulset/statefulset.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/busybox-statefulset/statefulset.yaml b/busybox-statefulset/statefulset.yaml index 52bb1dc..125f39f 100644 --- a/busybox-statefulset/statefulset.yaml +++ b/busybox-statefulset/statefulset.yaml @@ -4,6 +4,12 @@ kind: StatefulSet metadata: name: busybox spec: + # Required for proper clean up on failover and successful relocate. You + # must enable the StatefulSetAutoDeletePVC feature gate for this. + # https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention + persistentVolumeClaimRetentionPolicy: + whenDeleted: Delete + whenScaled: Retain selector: matchLabels: appname: busybox