StatefulSet Basics
Provide stable identity and storage for stateful workloads.
StatefulSet is built for databases and queues. The key idea is stable identity plus stable storage.
Typical features
- Fixed Pod names (like
mysql-0) - One PVC per Pod
- Ordered startup and rolling updates
Core snippet
spec:
serviceName: mysql
replicas: 3
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
Tips
- Pair with a Headless Service
- Validate with a single replica before scaling
Practical notes
- Start with a quick inventory:
kubectl get nodes,kubectl get pods -A, andkubectl get events -A. - Compare desired vs. observed state;
kubectl describeusually explains drift or failed controllers. - Keep names, labels, and selectors consistent so Services and controllers can find Pods.
Quick checklist
- The resource matches the intent you described in YAML.
- Namespaces, RBAC, and images are correct for the target environment.
- Health checks and logs are in place before promotion.