Why StatefulSet



Stateful

The main purpose of a StatefulSet is to provide a persistent identity to Pods as well as the Pod-specific storage.
Each pod in a StatefulSet has a persistent identifier that it keeps across rescheduling.
StatefulSet provides ordering as well. Using StatefulSet is valuable for applications that require any of the following
- Stable and unique network identifiers
- Stable persistent storage
- Ordered deployment and scaling
- Ordered automated rolling updates
StatefulSet Limitations
Storage Provisioning based on StorageClass must be available. To ensure data safety, volumes created by the StatefulSet are not deleted while deleting the StatefulSet.
- A Headless Service must be created to provide application access
- To guarantee removal of StatefulSet Pods, scale down the number of Pods to 0 before removing the StatefulSet
$ cat sfs.yaml
$ kubectl create -f sfs.yaml
$ kubectl get all
$ kubectl get pvc
Headless service
Sometimes you don’t need load-balancing and a single Service IP. In this case, you can create what are termed “headless” Services, by explicitly specifying "None" for the cluster IP (.spec.clusterIP).
For headless Services, a cluster IP is not allocated, kube-proxy does not handle these Services, and there is no load balancing or proxying done by the platform for them. How DNS is automatically configured depends on whether the Service has selectors defined.
podname.headless-servicename.namespace.svc.cluster-domain.example




Storage in stateful set

Volume claim template

We move it to the stateful definition:

How it all hangs together?
