chapter fifteen

15 Deploying stateful workloads with StatefulSets

 

This chapter covers

  • Managing stateful workloads via StatefulSet objects
  • Exposing individual Pods via headless Services
  • Understanding the difference between Deployments and StatefulSets
  • Automating stateful workload management with Kubernetes Operators

Each of the three services in your Kiada suite is now deployed via a Deployment object. The Kiada and Quote services each have three replicas, while the Quiz service has only one because its data doesn’t allow it to scale easily. In this chapter, you’ll learn how to properly deploy and scale stateful workloads like the Quiz service with a StatefulSet.

Before you begin, create the kiada Namespace, change to the Chapter15/ directory and apply all manifests in the SETUP/ directory with the following command:

$ kubectl apply -n kiada -f SETUP -R
IMPORTANT

The examples in this chapter assume that the objects are created in the kiada Namespace. If you create them in a different location, you must update the DNS domain names in several places.

NOTE

15.1 Introducing StatefulSets

Before you learn about StatefulSets and how they differ from Deployments, it’s good to know how the requirements of stateful workloads differ from those of their stateless counterparts.

15.1.1 Understanding stateful workload requirements

15.1.2 Comparing StatefulSets with Deployments

15.1.3 Creating a StatefulSet

15.1.4 Inspecting the StatefulSet, Pods, and PersistentVolumeClaims

15.1.5 Understanding the role of the headless Service

15.2 Understanding StatefulSet behavior

15.2.1 Understanding how a StatefulSet replaces missing Pods

15.2.2 Understanding how a StatefulSet handles node failures

15.2.3 Scaling a StatefulSet

15.2.4 Changing the PersistentVolumeClaim retention policy

15.2.5 Using the OrderedReady Pod management policy

15.3 Updating a StatefulSet

15.5 Summary