This page describes the use of StatefulSet objects in Google Kubernetes Engine (GKE). You can also learn how to Deploy a stateful application.
About StatefulSets
StatefulSets represent a set of Pods with unique, persistent identities, and stable hostnames that GKE maintains regardless of where they are scheduled. The state information and other resilient data for any given StatefulSet Pod is maintained in persistent volumes associated with each Pod in the StatefulSet. StatefulSet Pods can be restarted at any time.
For stateless applications, use Deployments.
StatefulSets function similarly in GKE and in Kubernetes. This document describes any GKE-specific considerations. To learn how StatefulSets work, see the Kubernetes documentation about StatefulSets.
Plan networking for StatefulSets
StatefulSets provide persistent storage in the form of a PersistentVolume and a unique network identity (hostname). The following table includes the caveats that application operators should be aware of when configuring a StatefulSet:
Networking caveat | Description | Best practice |
---|---|---|
GKE Services instead of fixed IP addresses |
Although Pod replicas have a unique ordinal index, support per-replica volumes, and network identity (hostname), the IP addresses that are assigned to a replica can change if GKE reschedules or evicts a Pod. |
To mitigate networking issues, the architecture should use Kubernetes Service resources. For more information, see Types of Kubernetes Services. |
Headless Services |
When initialized, a StatefulSet is paired with a matching headless service. |
Ensure that the `metadata.name` in
your Service matches the |
Peer discovery |
Stateful applications require a minimum number (quorum) of replicas to function with full availability. |
As Pods can crash, be rescheduled, or evicted, each replica in a StatefulSet should be able to leave and rejoin quorum. Applications that require peering should have the capability to discover other peers through headless Services in Kubernetes. |
Health check based on readiness probes and liveness probes |
Your application should have properly configured readiness, liveness, and startup probes where applicable. Selecting timeouts for each probe is dependent on the requirements of your application. |
For readiness probes, follow these best practices to configure your application to mark readiness when it is ready to serve traffic:
|
To read more about probes, see Configure Liveness, Readiness, and Startup Probes.
Work with StatefulSets
To learn how to deploy StatefulSets in your GKE cluster and interact with them, see the Kubernetes documentation about StatefulSet basics.
What's next
- Learn how to deploy a stateful application
- Learn how to update StatefulSets using rolling updates
- Learn more about deploying workloads in GKE
- Read more about StatefulSets in the Kubernetes documentation
- Take a tutorial about upgrading a cluster running a stateful workload