Inferensys

Glossary

StatefulSet (Kubernetes)

A Kubernetes workload API object used to manage stateful applications, providing stable, unique network identifiers and persistent storage volumes for each pod replica.
Developer working on RAG retrieval system, document chunks visible on screen, technical workspace with code editor.
KUBERNETES WORKLOAD

What is StatefulSet (Kubernetes)?

A StatefulSet is a core Kubernetes API object designed to manage stateful applications by providing stable, predictable identities and persistent storage for each pod replica.

A StatefulSet is a Kubernetes workload controller that manages the deployment and scaling of a set of stateful Pods, providing guarantees about the ordering and uniqueness of these Pods. Unlike a Deployment, which treats pods as stateless, interchangeable units, a StatefulSet maintains a sticky identity for each of its Pods. This identity, based on a stable ordinal index (e.g., app-0, app-1), persists across Pod rescheduling and is coupled with stable network identifiers and persistent storage volumes.

This architecture is essential for applications like databases (e.g., MySQL, Cassandra), message queues, and other clustered services that require stable network endpoints and durable data. The StatefulSet ensures ordered, graceful deployment and scaling—pods are created sequentially and terminated in reverse order. Each pod's PersistentVolumeClaim template creates a unique, persistent storage volume that follows the pod, even if it is rescheduled to a different node, enabling true state persistence for agentic systems and data services.

KUBERNETES WORKLOAD

Key Features of StatefulSets

A StatefulSet is a Kubernetes workload API object used to manage stateful applications, providing stable, unique network identifiers and persistent storage volumes for each pod replica.

01

Stable, Unique Network Identity

Each pod in a StatefulSet receives a stable hostname based on the pattern <statefulset-name>-<ordinal-index> (e.g., web-0, web-1). This identity persists across pod rescheduling. A headless Service (ClusterIP: None) controls the network domain, allowing direct DNS resolution to each pod. This is critical for applications like databases (e.g., MongoDB, Cassandra) where nodes need to discover each other by stable names.

  • Predictable Naming: Pods are created sequentially from index 0.
  • DNS Records: Each pod gets a DNS entry: pod-name.service-name.namespace.svc.cluster.local.
02

Ordered, Graceful Deployment & Scaling

Pods are deployed, scaled, and terminated in a strict ordinal order (0, 1, 2...). This ensures controlled rollouts and is essential for systems with primary/replica relationships.

  • Rolling Updates: On update, pods are terminated and recreated in reverse order, one at a time.
  • Ordered Scaling: Scaling up creates pods in order (e.g., app-2 after app-1). Scaling down terminates pods in reverse order.
  • Pod Management Policy: The podManagementPolicy field can be set to Parallel to relax ordering for applications that don't require it.
03

Persistent, Pod-Specific Storage

StatefulSets use PersistentVolumeClaims (PVCs) templates to provision durable storage. A unique PVC is created for each pod and follows it for its lifetime, even if the pod is rescheduled to another node. This provides stable storage identity, preventing data loss.

  • Volume Claim Templates: Defined in spec.volumeClaimTemplates.
  • Sticky Identity: PVC for web-0 is always mounted to the pod web-0.
  • Storage Class: Can specify a storageClassName for dynamic provisioning (e.g., gp2, fast-ssd).
04

Stable Persistent Identifiers

The combination of stable network identity and persistent storage creates a stable persistent identifier for each pod instance. This allows stateful applications to reliably reference specific instances and their data. The identity is composed of:

  • Ordinal Index: The immutable sequence number.
  • Stable Hostname: Derived from the ordinal.
  • Stable Storage: The PVC bound to that specific ordinal.

This trio is fundamental for clustering, leader election, and data sharding patterns.

05

Use Cases & Typical Applications

StatefulSets are designed for applications that require one or more of: stable identity, stable storage, ordered deployment, or discovery via DNS.

Common Examples:

  • Databases: MySQL clusters, PostgreSQL with streaming replication, MongoDB replica sets, Cassandra rings.
  • Message Queues: Apache Kafka brokers, RabbitMQ clusters.- Distributed Data Stores: Elasticsearch, etcd, ZooKeeper ensembles.
  • Any application where a pod needs to retain its name and data after a restart.
06

Contrast with Deployments & DaemonSets

Understanding the difference clarifies when to use a StatefulSet.

  • vs. Deployment: Deployments manage stateless pods. Pods are fungible, have random hashes in their names (app-5f8c6d), and share storage volumes. Use Deployments for web servers, APIs, or workers.
  • vs. DaemonSet: DaemonSets run one pod per node (e.g., logging agents, storage daemons). Pod naming is node-based, not ordinal. DaemonSets are for node-level infrastructure, not clustered applications.

Key Distinction: If your pods are not interchangeable and need unique, stable identities, use a StatefulSet.

KUBERNETES STATE MANAGEMENT

How StatefulSets Work

A StatefulSet is a Kubernetes workload API object used to manage stateful applications, providing stable, unique network identifiers and persistent storage volumes for each pod replica.

A StatefulSet manages the deployment and scaling of a set of Pods while providing guarantees about the ordering and uniqueness of these pods. Unlike a Deployment, it maintains a sticky identity for each pod, defined by a persistent ordinal index (e.g., app-0, app-1). This identity is tied to stable network identifiers via a Headless Service and persistent PersistentVolumeClaims, ensuring pods can be rescheduled with the same storage and hostname. This architecture is essential for applications like databases (e.g., Cassandra, MongoDB) that require stable membership and individual storage.

The controller enforces strict ordering during operations: pods are created sequentially in ascending order and terminated in reverse order. Each pod's PersistentVolumeClaim template is instantiated individually, binding a unique PersistentVolume to that specific pod ordinal for its lifetime. This provides durable, pod-specific storage that survives rescheduling. The combination of stable network identity (via DNS records), ordered deployment, and persistent storage makes the StatefulSet the fundamental Kubernetes primitive for deploying and managing stateful applications in a cloud-native environment.

KUBERNETES

Frequently Asked Questions

A StatefulSet is a core Kubernetes workload controller for deploying and scaling stateful applications. It provides guarantees about the ordering and uniqueness of pods, along with stable network identities and persistent storage.

A StatefulSet is a Kubernetes workload API object used to manage stateful applications by providing stable, unique network identifiers, ordered deployment and scaling, and persistent storage volumes that are bound to individual pod instances. Unlike a Deployment, which manages stateless pods as interchangeable replicas, a StatefulSet maintains a sticky identity for each of its pods (named -0, -1, etc.). This identity persists across pod rescheduling, enabling applications like databases (e.g., Cassandra, MongoDB, etcd), message queues, and other clustered services that require stable network endpoints and durable storage.

Key characteristics include:

  • Stable Pod Hostname: Each pod derives its hostname from the pattern $(statefulset name)-$(ordinal). The pod web-0 will always be web-0.
  • Stable Storage: PersistentVolumeClaims (PVCs) created from the StatefulSet's volumeClaimTemplates are bound to the specific pod ordinal, following it even if the pod is rescheduled to another node.
  • Ordered, Graceful Deployment & Scaling: Pods are created, updated, and terminated in a strict sequential order (e.g., web-0, then web-1). Scaling down removes pods in reverse order.
  • Ordered, Graceful Rolling Updates: Updates follow the same pod order, ensuring only one pod is down at a time during a rolling update.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.