[SHORT] Extending Kubernetes StatefulSet PVC Without Downtime
Kubernetes troubleshooting series
Problem
In Kubernetes, the size of a Persistent Volume Claim (PVC) cannot be directly updated for a StatefulSet object. This limitation exists because the PVC is bound to a Persistent Volume (PV) that has a fixed capacity.
When you create a PVC for a StatefulSet, it requests a specific amount of storage capacity. This request is fulfilled by binding the PVC to an available PV that meets the capacity requirement. Once the PVC is bound to a PV, the capacity cannot be changed because it would require modifying the underlying storage resource.
Solution
To extend the size of a PVC in a StatefulSet, you generally need to follow these steps:
- Update the PVC object
Make sure that your StorageClass has ALLOWVOLUMEEXPANSION=true
property
$ kubectl edit pvc <YOUR_PVC_NAME> # Change "storage" from both places
$ kubectl describe pvc <YOUR_STATEFULSET_NAME> # Now when you describe your PVC you should see the changes
2. Delete the StatefulSet object
$ kubectl delete sts --cascade=orphan <YOUR_STATEFULSET_NAME> # Use the flag --cascade=orphan to delete the StatefulSet and keep its pods running
3. Update the StatefulSet manifest and redeploy it
$ kubectl apply -f sts.yaml # Before applying you need to change the "storage" size as well in sts.yaml file
$ kubectl rollout restart sts <YOUR_STATEFULSET_NAME> # Restart the pods one at a time, the pod's PVC will be extended during the restart
Thanks for reading. I hope this short story was helpful. If you are interested, check out my other Medium articles.