Workloads
StatefulSet
50 / 82

When "which replica am I" and "my own disk" matter, use a StatefulSet.

Deployment Pods are interchangeable and randomly named. StatefulSet Pods have stable names, stable DNS and their own PVC that follows them.

Deployment

random names, any order, shared or no storage

x7k2pm3n9qr8t4z
StatefulSet postgres

stable ordinals, created in order, each with its own PVC

pg-0โ†’ pvc data-pg-0
pg-1โ†’ pvc data-pg-1
pg-2โ†’ pvc data-pg-2

Ordered lifecycle

Created 0, 1, 2 (each Ready first). Scaled down from the highest ordinal. Updated in reverse order, so pg-0 is touched last.

Headless Service gives DNS per Pod

pg-0.postgres.shop.svc.cluster.local always reaches pg-0, even after it moves nodes.

Manual canary with partition

partition: 2 updates only pg-2. Verify, then lower the number to roll out further.

volumeClaimTemplates:
- metadata: {name: data}
  spec: {accessModes: [ReadWriteOnce], resources: {requests: {storage: 20Gi}}}