Summary - StatefulSet
- Docker & Kubernetes course
- Advanced
- Lesson 18/70
- 5 min
Combine YAML and volumeClaimTemplate to write a StatefulSet.
Summary: StatefulSet
In this group:
- A StatefulSet is for stateful applications: stable ordinal names, stable network names, persistent storage per pod.
serviceNamepoints at a headless service (clusterIP: None); pod DNS isdb-0.db.volumeClaimTemplatescreates a PVC (data-db-0) for each pod; PVCs remain when the pod and StatefulSet are deleted.OrderedReadystarts in order and scales down in reverse;Parallelstarts without waiting.- Updates proceed in reverse;
partitionenables canary updates.
kubectl get sts,pvc -l app=db
kubectl scale sts db --replicas=5Practice The headless service
Write a Service YAML: name db; clusterIP: None; selector app: db; port 5432.
Starter code
# buraya yazSample solution
apiVersion: v1
kind: Service
metadata:
name: db
spec:
clusterIP: None
selector:
app: db
ports:
- port: 5432Expected output
service/db created NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE db ClusterIP None <none> 5432/TCP 1s
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the reason to choose a Deployment instead of a StatefulSet for a web API?
- A Deployment needs less YAML
- Replicas are interchangeable; no stable identity or per-pod disk is needed Correct answer
- StatefulSets are slow
- StatefulSets can't scale
Explanation: Stateless applications update faster and more flexibly with a Deployment.
2 Scale the StatefulSet.
kubectl scale ____ db --replicas=5
kubectl scale sts db --replicas=5
Explanation: A StatefulSet is also scaled with scale.
3 Match.
| Term | Meaning |
|---|---|
StatefulSet |
Stateful |
Deployment |
Stateless |
headless |
Pod DNS records |
partition |
Canary |