liveBook · Manning

Statefulness

As explained in Road to Kubernetes

A stateful containerized application is a containerized application whose behavior or data depends on persistent state across operations or restarts.

Statefulness means that an application depends on data or behavior that must persist across operations or machine restarts. Databases are the clearest example: destroying their machine can destroy their data unless backup data exists. Containerized applications with this requirement are more difficult because containers are designed to be stateless, while many stateful systems were not designed for container or cluster operation. section 1.6 section 5.1.4

Use these contrasts to recognize statefulness:

  • A stateless Python or Node.js application can be recreated after its machine is destroyed because its environment is described by requirements.txt or package.json. section 5.1.4
  • A stateful database needs its data to persist somewhere; destroying the running machine can otherwise cause permanent data loss. section 5.1.4
  • Stateful containerized applications commonly depend on communication with stateless application containers, such as a database serving a Python or Node.js application. section 6.4

Why modifying a running container is not persistence

Running docker run --rm -it ubuntu /bin/bash, installing NGINX, and then exiting creates only a temporary change. Starting the container again produces errors because the installed NGINX is gone. The repeatable fix is to modify the container image rather than rely on changes made inside an existing container. section 5.1.4

docker run --rm -it ubuntu /bin/bash
cat /etc/nginx/sites-available/default
nginx -v
exit

Inspect the short command sequence that demonstrates temporary container changes and their disappearance after removal. section 5.1.4

How Road to Kubernetes covers it

How deep it goes
Defines statefulness, contrasts it with stateless containers, and demonstrates temporary changes without detailing persistent-storage implementation.
Examples
Uses databases, Python and Node.js applications, and an Ubuntu container with an installed NGINX server.
What it assumes
Assumes basic containers and applications, while introducing the stateless-versus-stateful distinction through concrete Docker commands.
What you can do after
Evaluate/understand why databases need persistence and why container images should replace ad hoc changes inside running containers.
How it connects
Connects statefulness with databases, containers, backups, Docker Compose networking, Kubernetes, and stateless applications.

Also explained in

Compare how 14 books explain statefulness →

Related concepts

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