You already deployed your applications to your cluster using Deployments and ReplicaSets, however, these resources are unsuitable for stateful applications such as databases. Learn more about stateful applications and find out how to deploy them in Kubernetes.
In Kubernetes, deploying stateless applications is easy. You can use a Deployment, which creates a ReplicaSet, which, in turn, creates Pods. If one Pod fails, the ReplicaSet creates a new one. These Pods are identified based on their specification and applied labels. However, Pods created by ReplicaSet have a random hash assigned at the end of their name, such as hello-kyma-59fd556764-fkr6d. This is because the Pods are stateless and can be replaced by any other Pod with the same specifications and labels.
Instead, stateful applications often need a unique and consistent identifier, such as a stable hostname. This makes it tricky with the nature of ReplicaSets, since they would randomly assign a new name to the Pod, making it hard to identify the Pod and connect to it. For this reason, Kubernetes provides StatefulSets.
Based on the official Kubernetes documentation, you can use StatefulSets when your workload requires one or more of the following features:
- Stable, unique network identifiers
- Stable, persistent storage
- Ordered, graceful deployment and scaling
- Ordered automated rolling updates
So, a StatefulSet manages a group of Pods with unique, persistent identities and stable hostnames that Kubernetes maintains across rescheduling.
