Understanding StatefulSets
StatefulSets are very similar to ReplicaSets and Deployments, but with one key difference that makes them better for stateful workloads. StatefulSets maintain the order and identity of each Pod, even if the Pods are rescheduled onto new nodes.
For instance, in a StatefulSet of 3 replicas, there will always be Pod 1, Pod 2, and Pod 3, and those Pods will maintain their identity in Kubernetes and storage (which we'll get to in Chapter 7, Storage on Kubernetes), regardless of any rescheduling that happens.
Let's take a look at a simple StatefulSet configuration:
statefulset.yaml
apiVersion: apps/v1 kind: StatefulSet metadata:   name: stateful spec:   selector:     matchLabels:       app: stateful-app   replicas: 5   template:     metadata:       labels:        &...