liveBook · Manning

Statefulness

As explained in Kubernetes in Action, Second Edition

A stateful backend is a backend application component whose operation depends on retained application or client state.

Statefulness means that an application depends on retained state to function. That state must survive restarts and relocation, so stateful workloads require more careful storage, identity, and scaling decisions than stateless workloads. section 16.1.1

Stateful workloads differ from stateless replicas in several practical ways:

  • Replicas cannot always be added or removed freely because each instance may own or depend on particular state. section 16.1.1
  • Shared state requires storage that supports concurrent read-write access; otherwise, each replica needs its own volume. section 16.1.1
  • A replacement instance must retain the former instance’s network identity and state rather than behaving as an interchangeable copy. section 16.1.2

Scaling the Quiz service

Scaling the Quiz Deployment from one to three replicas can leave new pods unable to start when all replicas use one ReadWriteOnce volume. A MongoDB container may fail because another instance already holds the database lock. section 16.1.1

Kubernetes manages stateful workloads with StatefulSets. Each replica receives an ordinal name and its own PersistentVolumeClaim, while a headless Service can provide a stable DNS record even after pod relocation. StatefulSets also control creation and deletion order, update behavior, and claim retention; complex applications may require Operators. section 16.1.2 section 16.5

$ kubectl scale deploy quiz --replicas 3
deployment.apps/quiz scaled

Inspect the practical failure mode by scaling the Quiz Deployment and then checking the resulting pods. section 16.1.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains storage conflicts, replica identity, lifecycle behavior, and Kubernetes automation without detailing application-specific state management.
Examples
Uses the Quiz service, MongoDB volume locking, ordinal pods, per-replica claims, and the pets-versus-cattle analogy.
What you can do after
Operate/configure stateful workloads with StatefulSets, per-replica storage, stable identities, and lifecycle policies.
How it connects
Connects statefulness with StatefulSets, Deployments, PersistentVolumes, PersistentVolumeClaims, headless Services, and Kubernetes Operators.

Also explained in

Compare how 14 books explain statefulness →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.