apiVersion: apps/v1
kind: StatefulSet
metadata:name: mysql
spec:replicas:3serviceName: mysql-h # must match headless Service nameselector:matchLabels:app: mysql
podManagementPolicy: OrderedReady # or ParallelupdateStrategy:type: RollingUpdate # default; or OnDeleterollingUpdate:partition:0# only Pods with ordinal >= partition are updatedtemplate:spec:containers:-name: mysql
image: mysql
volumeClaimTemplates:# PVC per Pod: data-volume-mysql-0, etc.-metadata:name: data-volume
spec:accessModes:[ReadWriteOnce]resources:requests:storage: 500Mi
updateStrategy
Type
Behaviour
RollingUpdate (default)
Updates Pods in reverse ordinal order (highest first)
OnDelete
No automatic update; Pod updated only when manually deleted
partition: only Pods with ordinal ≥ partition are updated → staged rollout
e.g. partition: 2 with 3 replicas: only mysql-2 updated; mysql-0, mysql-1 stay on old version
Headless Service
clusterIP: None: DNS record per Pod, not one cluster IP
Service name must match StatefulSet serviceName
apiVersion: v1
kind: Service
metadata:name: mysql-h
spec:clusterIP: None
selector:app: mysql
ports:-port:3306
DNS: mysql-0.mysql-h.default.svc.cluster.local (not load-balanced random Pod)