StatefulSet
Retain Reclaim Policy
PersistentVolume
Kubernetes
Storage Management

StatefulSet vs Retain reclaim policy of a PersistentVolume

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

StatefulSet and a PersistentVolume's Retain reclaim policy solve different problems, so comparing them directly can be confusing. A StatefulSet manages stable pod identity and per-replica storage claims, while a Retain reclaim policy controls what happens to the underlying volume after its claim is released.

What a StatefulSet Actually Guarantees

StatefulSet is a workload controller for stateful applications. It gives each pod a stable ordinal identity and pairs well with volumeClaimTemplates so each replica gets its own persistent volume claim.

yaml
1apiVersion: apps/v1
2kind: StatefulSet
3metadata:
4  name: db
5spec:
6  serviceName: db
7  replicas: 2
8  selector:
9    matchLabels:
10      app: db
11  template:
12    metadata:
13      labels:
14        app: db
15    spec:
16      containers:
17        - name: postgres
18          image: postgres:16
19          volumeMounts:
20            - name: data
21              mountPath: /var/lib/postgresql/data
22  volumeClaimTemplates:
23    - metadata:
24        name: data
25      spec:
26        accessModes:
27          - ReadWriteOnce
28        resources:
29          requests:
30            storage: 10Gi

That setup ensures each pod such as db-0 and db-1 gets its own persistent claim, but it does not by itself decide whether the underlying storage is deleted or retained after release.

What Retain Means on a PersistentVolume

The reclaim policy belongs to the PersistentVolume, not the StatefulSet. Retain means that when the PVC releases the PV, Kubernetes does not automatically delete the underlying storage asset.

That is a storage-lifecycle decision, not a pod-identity decision.

In other words:

  • 'StatefulSet answers "which pod gets which stable storage claim"'
  • 'Retain answers "what happens to the backing volume after the claim is gone"'

Why They Are Often Mentioned Together

People discuss them together because stateful apps often care deeply about data survival. If a database runs in a StatefulSet, you may also want the backing volumes preserved after accidental PVC deletion.

But the features remain orthogonal. You can have:

  • a StatefulSet with PVs that delete automatically
  • a StatefulSet with retained PVs
  • non-StatefulSet workloads using retained PVs

The controller type and the reclaim policy are separate layers of the design.

Example Storage Lifecycle Difference

Suppose a dynamically provisioned volume comes from a storage class whose reclaim policy is Delete. If the related PVC is deleted, the backing volume may be deleted too, even if that PVC originally came from a StatefulSet-managed claim template.

If the PV reclaim policy is Retain, the underlying disk remains after claim release, and you usually need manual cleanup or manual reattachment later.

That is why using a StatefulSet does not automatically mean data is protected from storage deletion.

Design Implications

If your main requirement is stable pod identity plus one volume per replica, use a StatefulSet.

If your main requirement is "never automatically delete the underlying disk," look at reclaim policy and, depending on your storage workflow, PVC retention behavior as well.

For critical data systems, you usually think about both layers together:

  • Stateful workload behavior
  • PVC lifecycle
  • PV reclaim behavior
  • backup and restore strategy

Kubernetes persistence is reliable only when those pieces are aligned.

Common Pitfalls

The biggest pitfall is assuming StatefulSet implies retained storage. It does not.

Another issue is focusing only on the workload manifest and ignoring the storage class or PV behavior underneath it. The actual deletion semantics often come from the storage layer, not the controller.

Developers also sometimes confuse PVC retention with PV reclaim policy. A claim surviving longer and a backing disk surviving release are related but different lifecycle concerns.

Finally, do not treat Retain as a backup strategy. It prevents automatic deletion, but it does not replace snapshots, backups, or restore planning.

Summary

  • 'StatefulSet manages stable identity and predictable persistent claims for stateful pods.'
  • 'Retain reclaim policy controls whether the backing volume is preserved after claim release.'
  • These features are complementary, not alternatives.
  • A StatefulSet can still use storage that is deleted automatically if the PV or storage class says so.
  • For stateful systems, align controller choice, PVC lifecycle, PV reclaim behavior, and backup strategy deliberately.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.