Hands-on Lab·Certified Kubernetes Administrator
Storage for StatefulSets: volumeClaimTemplates
volumeClaimTemplates gives every replica its own claim, named by ordinal. Delete a Pod and its data comes back; scale down or delete the whole StatefulSet and the claims stay behind, which is deliberate and is the thing that surprises people.
Storage Guide 73 of 103 Intermediate
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 35 min
PVC names are generated deterministically. That predictability is the feature, not an implementation detail.
- Provisionerrancher.io/local-path
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when every replica of a workload needs a disk of its own. This matters because volumeClaimTemplates binds a volume to the ordinal rather than to the Pod, and nothing you do to the StatefulSet will ever delete those claims for you.
- using
volumeClaimTemplatesto give each replica its own claim, named deterministically by ordinal - deleting a Pod and watching the same volume come back attached to the same ordinal
- scaling up to get a new claim, then scaling down and finding the old one still there
- deleting the StatefulSet outright and finding every claim still present
Before you start
- The StatefulSets guide, for stable identity and ordered rollout.
- The dynamic provisioning guide, since each generated claim provisions a volume.
- The reclaim policies guide, for what happens to the claims this guide leaves behind.
-
volumeClaimTemplates, and the names it generates
-
The volume belongs to the ordinal, not to the Pod
-
Scaling up creates a claim; scaling down does not remove one
-
Deleting the StatefulSet keeps them too