Increase Replica With Volume of Arbitrary Size With K8s Stateful Set

Photo by patricia serna on Unsplash

Introduction

Once Statefulset is deployed, volumeClaimTemplates etc. cannot be changed. However, there is a way to change the Volume.

As a result, the volume size in volumeClaimTemplates on the code and the size actually used are different. In that state, if you try to Scale, the volume and size that have already been expanded will be different, and the balance will be lost.

Solution

Create PVC

The pvc created from VolumeClaimTemplate is, <volumeClaimTemplateName>-<pod_name>so in this case it was test-storage-4-testing.

...
volumeClaimTemplates:
- metadata:
name: test-storage
annotations:
volume.beta.kubernetes.io/storage-class: gp2-topology-aware
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
volume.beta.kubernetes.io/storage-class: gp2-topology-aware
name: test-storage-4-testing
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi

At this time, if volumeBindingMode: WaitForFirstConsumer you are using it, wait until the pod claims and the following message appears

Normal WaitForFirstConsumer 11s (x3 over 20s) persistentvolume-controller waiting for first consumer to be created before binding