Stateful vs Stateless

A stateless application doesn’t manage its state in the Kubernetes cluster. All of the states are stored outside the cluster and the cluster containers access it in some manner.

A stateful application can remember at least some things about its state each time that it runs. The actual state data that it stores may depend on the application and on the conditions under which it operates.

Here, “State” refers to any changeable condition, including the results of internal operations, interactions with other applications or services, environment variables, the contents of memory or temporary storage, or files opened, read from, or written to.

Deployments and ReplicaSets are meant for stateless usage and are rather lightweight.

StatefulSets are used when the state has to be persisted. Therefore the latter use volumeClaimTemplates / claims on persistent volumes to ensure they can keep the state across component restarts.

So if your application is stateful or if you want to deploy stateful storage on top of Kubernetes use a StatefulSet.

If your application is stateless or if the state can be built up from backend-systems during the start then use Deployments.

Stateless

  • No Persistent Storage
  • Scaling can be done independently
  • Mortal

Stateful

  • Stable, unique network identifiers
  • Stable, persistent storage
  • Ordered, graceful deployment and scaling
  • Ordered, graceful deletion and termination