Expanding a StatefulSet controller volume
To increase the size of a volume for the StatefulSet controller:
- Create a StatefulSet controller.
- Make changes to controller settings.
- Create a controller with new PersistentVolumeClaim settings.
Warning
While the instruction is running, the number of the controller's pods will drop to zero, which will make the service unavailable.
Create a StatefulSet controller
-
Create a file called
sts.yaml
with a controller configuration:sts.yamlapiVersion: 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"] volumeClaimTemplates: - metadata: name: pvc-dynamic spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "nebius-network-ssd" 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 for each pod is 1 GB. -
Make sure that the controller's pods have transitioned to the
Running
state 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-feaad7fac9c0 1Gi RWO nebius-network-ssd 91s persistentvolumeclaim/pvc-dynamic-ubuntu-test-1 Bound pvc-a6fb0761-0771-483c-abfb-d4a89ec4719f 1Gi RWO nebius-network-ssd 81s persistentvolumeclaim/pvc-dynamic-ubuntu-test-2 Bound pvc-f479c8aa-426a-4e43-9749-5e0fcb5dc140 1Gi RWO nebius-network-ssd 73s
-
Make sure that for objects with the
k8s-csi
prefix, the disks have transitioned toREADY
status:ncp compute disk list
Command result:
+----------------------+--------------------------------------------------+-------------+-------------------+--------+----------------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+--------------------------------------------------+-------------+-------------------+--------+----------------------+-------------+ | ef3b5ln111s36h0ugf7c | k8s-csi-15319ac44278c2ff23f0df04ebdbe5a8aa6f4a49 | 1073741824 | eu-north1-c | READY | ef3nrev9j72tpte4vtac | | | ef3e617rmqrijnesob0n | k8s-csi-336f16a11f750525075d7c155ad26ae3513dca01 | 1073741824 | eu-north1-c | READY | ef3nrev9j72tpte4vtac | | | ef3rfleqkit01i3d2j41 | k8s-csi-ba784ddd49c7aabc63bcbfc45be3cc2e279fd3b6 | 1073741824 | eu-north1-c | READY | ef3nrev9j72tpte4vtac | | +----------------------+--------------------------------------------------+-------------+-------------------+--------+----------------------+-------------+
Make changes to controller settings
-
Save the current
ubuntu-test
controller configuration to a file calledubuntu-test-sts.yaml
:kubectl get sts ubuntu-test --output yaml > ubuntu-test-sts.yaml
-
In
ubuntu-test-sts.yaml
, increase the value for thevolumeClaimTemplates.spec.resources.requests.storage
parameter from1Gi
to2Gi
:... spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
Note
There is no need to increase the corresponding value of
1Gi
for thekubectl.kubernetes.io/last-applied-configuration
parameter. -
Reduce the number of
ubuntu-test
controller pods to zero:kubectl scale statefulset ubuntu-test --replicas=0
-
Wait for the controller to complete scaling. To monitor the status of pod deletion, use the command below:
kubectl get pods
The controller has finished scaling when there are no pods with the
pod/ubuntu-test-
prefix in the command result. -
Make sure that for objects with the
k8s-csi
prefix, the disks have an emptyINSTANCE IDS
:ncp compute disk list
Result:
+----------------------+--------------------------------------------------+-------------+--------------------+--------+----------------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+--------------------------------------------------+-------------+--------------------+--------+----------------------+-------------+ | ef3b5ln111s36h0ugf7c | k8s-csi-15319ac44278c2ff23f0df04ebdbe5a8aa6f4a49 | 1073741824 | eu-north1-c | READY | | | | ef3e617rmqrijnesob0n | k8s-csi-336f16a11f750525075d7c155ad26ae3513dca01 | 1073741824 | eu-north1-c | READY | | | | ef3rfleqkit01i3d2j41 | k8s-csi-ba784ddd49c7aabc63bcbfc45be3cc2e279fd3b6 | 1073741824 | eu-north1-c | READY | | | +----------------------+--------------------------------------------------+-------------+--------------------+--------+----------------------+-------------+
-
Delete the current
ubuntu-test
StatefulSet controller:kubectl delete statefulset ubuntu-test --cascade=orphan
-
Make sure that the StatefulSet controller is deleted:
kubectl get sts
Create a controller with new PersistentVolumeClaim settings
-
Update the settings for each PersistentVolumeClaim controller:
kubectl patch pvc pvc-dynamic-ubuntu-test-0 --patch '{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}' && \ 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"}}}}'
-
Create a StatefulSet controller with more storage:
kubectl apply -f ubuntu-test-sts.yaml
-
Make sure that a new StatefulSet controller comprising three pods has been created:
kubectl get sts,pods
Result:
NAME READY AGE statefulset.apps/ubuntu-test 3/3 15s NAME READY STATUS RESTARTS AGE pod/ubuntu-test-0 1/1 Running 0 16s pod/ubuntu-test-1 1/1 Running 0 13s pod/ubuntu-test-2 1/1 Running 0 10s
-
Make sure that PersistentVolume for the
ubuntu-test
controller has 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-feaad7fac9c0 2Gi RWO Delete Bound default/pvc-dynamic-ubuntu-test-0 nebius-network-ssd 11m pvc-a6fb0761-0771-483c-abfb-d4a89ec4719f 2Gi RWO Delete Bound default/pvc-dynamic-ubuntu-test-1 nebius-network-ssd 11m pvc-f479c8aa-426a-4e43-9749-5e0fcb5dc140 2Gi RWO Delete Bound default/pvc-dynamic-ubuntu-test-2 nebius-network-ssd 11m