Scaling StatefulSets
Learn how to scale StatefulSets up and down.
We'll cover the following...
Each time Kubernetes scales up a StatefulSet, it creates new Pods and PVCs. However, when scaling down, Kubernetes only terminates Pods. This means future scale-up operations only need to create new Pods and connect them back to the original PVCs. Kubernetes and the StatefulSet controller handle all of this without our help.
Modifying the replica count
We currently have three StatefulSet Pods and three PVCs. Edit the sts.yml
file, change the replica count from 3 to 2, and save the changes.
apiVersion: apps/v1 kind: StatefulSet metadata: name: tkb-sts spec: replicas: 2 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: 1Gi
Playground
Once done, run the following command to repost the updated configuration to the cluster. You’ll have to type exit
if you’re still logged on to the jump Pod.
$ kubectl apply -f sts.ymlstatefulset.apps/tkb-sts configured
Create the StatefulSet
Check ...