16 Handling Stateful Applications 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 Chapter16/ 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

16.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.

16.1.1 Understanding stateful workload requirements

16.1.2 Comparing StatefulSets with Deployments

16.1.3 Creating a StatefulSet

16.1.4 Inspecting the StatefulSet, Pods, and PersistentVolumeClaims

16.1.5 Understanding the role of the headless Service

16.2 Understanding StatefulSet behavior

16.2.1 Understanding how a StatefulSet replaces missing Pods

16.2.2 Understanding how a StatefulSet handles node failures

16.2.3 Scaling a StatefulSet

16.2.4 Changing the PersistentVolumeClaim retention policy

16.2.5 Using the OrderedReady Pod management policy

16.3 Updating a StatefulSet

16.3.1 Using the RollingUpdate strategy

16.3.2 RollingUpdate with partition

16.3.3 OnDelete strategy

16.4 Managing stateful applications with Kubernetes Operators

16.4.1 Deploying the MongoDB community operator

16.4.2 Deploying MongoDB via the operator

16.4.3 Cleaning up

16.5 Summary