Increasing volume size for the StatefulSet controller
To increase volume size for the StatefulSet controller without shutting down the service:
Before you start, install kubectl
Create a StatefulSet controller
-
Create a file named
sts.yaml
with the controller configuration:sts.yaml
apiVersion: apps/v1 kind: StatefulSet metadata: name: ubuntu-test spec: selector: matchLabels: app: ubuntu serviceName: "ubuntu" replicas: 3 template: metadata: labels: app: ubuntu spec: terminationGracePeriodSeconds: 10 containers: - name: ubuntu image: ubuntu command: ["/bin/sh"] args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"] volumeMounts: - mountPath: /data name: pvc-dynamic volumeClaimTemplates: - metadata: name: pvc-dynamic spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "yc-network-hdd" resources: requests: storage: 1Gi
-
Create a controller:
kubectl apply -f sts.yaml
The command will create a StatefulSet controller named
ubuntu-test
comprising three pods. The size of PersistentVolumeClaim per pod is 1 GB. -
Make sure the controller pods changed their status to
Running
and PersistentVolumeClaim, toBound
:kubectl get pods,pvc
Result:
NAME READY STATUS RESTARTS AGE pod/ubuntu-test-0 1/1 Running 0 90s pod/ubuntu-test-1 1/1 Running 0 80s pod/ubuntu-test-2 1/1 Running 0 72s NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE persistentvolumeclaim/pvc-dynamic-ubuntu-test-0 Bound pvc-603ac129-fe56-400a-8481-feaa******** 1Gi RWO yc-network-hdd 91s persistentvolumeclaim/pvc-dynamic-ubuntu-test-1 Bound pvc-a6fb0761-0771-483c-abfb-d4a8******** 1Gi RWO yc-network-hdd 81s persistentvolumeclaim/pvc-dynamic-ubuntu-test-2 Bound pvc-f479c8aa-426a-4e43-9749-5e0f******** 1Gi RWO yc-network-hdd 73s
-
Make sure the disks for objects with the
k8s-csi
prefix changed their status toREADY
:yc compute disk list
Result:
+----------------------+--------------------------------------------------+------------+-------------------+--------+----------------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+--------------------------------------------------+------------+-------------------+--------+----------------------+-------------+ | ef3b5ln111s3******** | k8s-csi-15319ac44278c2ff23f0df04ebdbe5a8******** | 1073741824 | ru-central1-a | READY | ef3nrev9j72t******** | | | ef3e617rmqri******** | k8s-csi-336f16a11f750525075d7c155ad26ae3******** | 1073741824 | ru-central1-a | READY | ef3nrev9j72t******** | | | ef3rfleqkit0******** | k8s-csi-ba784ddd49c7aabc63bcbfc45be3cc2e******** | 1073741824 | ru-central1-a | READY | ef3nrev9j72t******** | | +----------------------+--------------------------------------------------+------------+-------------------+--------+----------------------+-------------+
Update controller settings
-
Save the current configuration of the
ubuntu-test
controller to a file namedubuntu-test-sts.yaml
:kubectl get sts ubuntu-test --output yaml > ubuntu-test-sts.yaml
-
In
ubuntu-test-sts.yaml
, increase thevolumeClaimTemplates.spec.resources.requests.storage
value from1Gi
to2Gi
:... spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
Note
You do not have to change the same
1Gi
value for thekubectl.kubernetes.io/last-applied-configuration
parameter. -
Delete the current StatefulSet controller named
ubuntu-test
:kubectl delete statefulset ubuntu-test --cascade=orphan
-
Make sure the StatefulSet controller has been deleted:
kubectl get sts
-
Delete the first pod named
ubuntu-test-0
:kubectl delete pod ubuntu-test-0
-
Update PersistentVolumeClaim of the
ubuntu-test-0
pod you deleted by increasing the storage size to 2 GB:kubectl patch pvc pvc-dynamic-ubuntu-test-0 --patch '{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}'
-
Apply the changes to the
ubuntu-test
controller:kubectl apply -f ubuntu-test-sts.yaml
-
Reduce the number of the
ubuntu-test
controller pods to 1:kubectl scale statefulset ubuntu-test --replicas=1
-
Increase the storage size for the
ubuntu-test-1
andubuntu-test-2
pods to 2 GB:kubectl patch pvc pvc-dynamic-ubuntu-test-1 --patch '{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}' && \ kubectl patch pvc pvc-dynamic-ubuntu-test-2 --patch '{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}'
-
Set the number of the
ubuntu-test
controller pods back to 3:kubectl scale statefulset ubuntu-test --replicas=3
-
Make sure PersistentVolume for the
ubuntu-test
controller has been increased to 2 GB for each volume:kubectl get pv
Result:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-603ac129-fe56-400a-8481-feaa******** 2Gi RWO Delete Bound default/pvc-dynamic-ubuntu-test-0 yc-network-hdd 11m pvc-a6fb0761-0771-483c-abfb-d4a8******** 2Gi RWO Delete Bound default/pvc-dynamic-ubuntu-test-1 yc-network-hdd 11m pvc-f479c8aa-426a-4e43-9749-5e0f******** 2Gi RWO Delete Bound default/pvc-dynamic-ubuntu-test-2 yc-network-hdd 11m