How To Increase the disk size of StatefulSet PVC

pie graph illustration
Reading Time: 2 minutes

Hi folks in this blog we will see How To Increase the disk size of Stateful PVC. When we edit the manifest file of Statefulset to increase the disk size of PVC and try to apply the changes it throughs an error. That means we can not edit the disk size of Statefulset by editing the manifest file to increase the disk size. So in this blog, we will see how we can increase the disk size of Statefulset without downtime.

Error when you try to apply the changes to the manifest.

spec: Forbidden: updates to statefulset spec for fields other than ‘replicas’, ‘template’, and ‘updateStrategy’ are forbidden

Usecase

Suppose you are using elastic search as a Statefulset with PVC to store the logs of your application and at some time you see that your index is showing yellow or red and this is because your elastic search storage is full. In that case, you have to increase the size of your Statefulset PVC but you don’t want any downtime.

Make sure storage-class ALLOWVOLUMEEXPANSION Is set to true

Increase the size of the PVC

First list the PVC that is bound with your Statefulset object. After that, you need to increase the size of each PVC using the kubectl command.

To list PVC use the following command:

kubectl get pvc -n <namespace>

To edit PVC use the following command

kubectl edit pvc <pvc-name> -n <namespace>

Under the spec section of your, PVC object increase the desired storage size and do the same with all bound PVCs.

Delete the Statefulset and Recreate the Statefulset

Deleting the Statefulset will not cause downtime as PVC will exist after even after deleting the Statefulset object. You will be able to use your stored volume. If you are using helm to deploy the Statefulset then follow the below step to Delete and recreate the Statefulset object.

To delete StatefulSet use this command

kubectl delete statefulset --cascade=orphan <statefulset_name> -n <namespace> 

–cascade=orphan flag will delete Statefulset only but your pod will remain running.

Now edit the helm chart with the updated PVC and use the below command to reinstall the chart to Recreate Statefulset.

helm upgrade <release_name> <chart_name> -n <namespace>

Now you will be able to see the new Statefulset is created with the updated PVC.

Conclusion

I hope now you are able to increase the disk size of the Statefulset PVC If you have any doubts or questions feel free to reach out to me or comment below. I hope you liked it Thank you.

References:

https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/

Written by 

Jubair Ahmad is a Software Consultant (DevOps)at Knoldus.Inc.He loves learning new technology and also have interest in playing cricket.

Leave a Reply