Search⌘ K
AI Features

Deploy the StatefulSet

Understand how to deploy StatefulSets in Kubernetes by defining replicas, services, and volume claim templates. Learn how StatefulSets manage ordered pod creation with persistent storage to support stateful applications and how to customize StorageClass settings for your environment.

We'll cover the following...

Now that we have a StorageClass and a headless Service, we can deploy the StatefulSet.

Example

The following YAML is from the sts.yml file and defines the StatefulSet.

YAML
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: tkb-sts
spec:
replicas: 3
selector:
matchLabels:
app: web
serviceName: "dullahan"
template:
metadata:
labels:
app: web
spec:
terminationGracePeriodSeconds: 10
containers:
- name: ctr-web
image: nginx:latest
ports:
- containerPort: 80
name: web
volumeMounts:
- name: webroot
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: webroot
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "flash"
resources:
requests:
storage: 10Gi

There’s a lot to take in, so let’s go through the ...