Cloud Native 7 min read

How Kubernetes 1.27 Handles StatefulSet PVC Deletion with New Retention Policies

Kubernetes 1.27 introduces a beta‑level StatefulSet PVC retention policy that lets users choose when PersistentVolumeClaims created by a StatefulSet are kept or removed, offering four configurable scenarios—Retain or Delete on deletion and scaling—along with practical examples and activation steps.

Cloud Native Technology Community
Cloud Native Technology Community
Cloud Native Technology Community
How Kubernetes 1.27 Handles StatefulSet PVC Deletion with New Retention Policies

Problem Addressed

Prior to the new feature, when a StatefulSet replica disappeared—either because the set was scaled down or the entire StatefulSet was deleted—the associated PersistentVolumeClaim (PVC) and its underlying volume remained, requiring manual cleanup. This caused unnecessary storage costs and operational overhead, especially for temporary data that could be regenerated.

New StatefulSet PVC Retention Policy

The beta‑stage StatefulSetAutoDeletePVC feature adds a policy to control the lifecycle of PVCs created from a volumeClaimTemplate. Two policy fields— whenDeleted and whenScaled —accept either Retain (keep the PVC) or Delete (remove the PVC). The policy is enforced via normal object deletion, ensuring that underlying PersistentVolumes follow the same retention rules.

Policy Matrix

whenDeleted = Retain & whenScaled = Retain : Matches the existing default behavior; PVCs are never deleted automatically. Suitable for irreplaceable data that should only be removed manually.

whenDeleted = Delete & whenScaled = Retain : PVCs are deleted only when the entire StatefulSet is removed. Scaling down retains PVCs, allowing them to be re‑attached if the set is later scaled up again. Ideal for short‑lived workloads such as CI jobs or ETL pipelines where data persists across a single run.

whenDeleted = Delete & whenScaled = Delete : PVCs are removed as soon as a replica is no longer needed, either by scaling down or by deleting the StatefulSet. This saves storage when data can be easily recreated.

whenDeleted = Retain & whenScaled = Delete : PVCs are kept when the StatefulSet is deleted but are removed during scaling down. This scenario is rarely useful; an example is an Elasticsearch cluster where you might temporarily shut down the whole set for maintenance, keeping the PVCs for a quick restart.

Next Steps

Enable the StatefulSetAutoDeletePVC feature gate in a Kubernetes 1.27 cluster, create a StatefulSet that specifies the desired retention policy, and observe the PVC behavior during scaling and deletion. Provide feedback to the SIG‑apps team.

References

StatefulSets

: https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/statefulset/ PersistentVolumeClaims: https://kubernetes.io/zh-cn/docs/concepts/storage/persistent-volumes/

Object deletion and garbage collection: https://kubernetes.io/zh-cn/docs/concepts/architecture/garbage-collection/

Official documentation of PVC policies: https://kubernetes.io/zh-cn/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-policies

CloudNativeKubernetesStatefulSetPVCBetaFeatureRetentionPolicy
Cloud Native Technology Community
Written by

Cloud Native Technology Community

The Cloud Native Technology Community, part of the CNBPA Cloud Native Technology Practice Alliance, focuses on evangelizing cutting‑edge cloud‑native technologies and practical implementations. It shares in‑depth content, case studies, and event/meetup information on containers, Kubernetes, DevOps, Service Mesh, and other cloud‑native tech, along with updates from the CNBPA alliance.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.