Controllers and Pod Recreation
Deployment Pods are interchangeable and named at random; StatefulSet Pods have stable identities and each keeps its own disk across deletion and rescheduling. That single difference is why databases use one and web front ends use the other. Both run in one namespace here, get the same Pod deleted, and are compared on the same screen.
Kubernetes Fundamentals Guide 10 of 46 Beginner
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 14 min
volumeClaimTemplates creates one PVC per replica, named <template>-<statefulset>-<ordinal>. Those PVCs are deliberately NOT deleted with the StatefulSet. persistentVolumeClaimRetentionPolicy can change that, and is left at its default here so the default behaviour is what you see.
| 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 you need to know whether a workload can be replaced freely or has an identity worth protecting. This matters because Deployment Pods are interchangeable and StatefulSet Pods are not, and deleting the wrong one can cost data.
- seeing StatefulSet Pods named by ordinal -
db-0,db-1- and created in order - writing a file to db-0's PersistentVolume, deleting the Pod, and finding the same name and the same file back
- running the same delete against a Deployment and watching entirely new random names appear
- confirming that deleting a StatefulSet leaves its PersistentVolumeClaims Bound
Before you start
- A cluster with a default StorageClass. This one uses
local-path, which provisions on first use. - The session creates namespace
kx-sts, a headless Servicedb, a StatefulSetdbwith two replicas and a 64Mi claim each, and a Deploymentwebwith two replicas for comparison.
-
Named in order, with a disk each
-
Write something only db-0 has
-
Delete it, and the same Pod comes back
-
The same test on a Deployment
-
What deleting the StatefulSet leaves behind