Statefulset: Resize PVC in volumeClaimTemplates
Revision | Date | Description |
|---|---|---|
| 24.07.2024 | Init Changelog |
Introduction
Kubernetes StatefulSets are used to deploy stateful applications inside your cluster. Each Pod in the StatefulSet can access local persistent volumes that stick to it even after it’s rescheduled. This allows Pods to maintain individual state that's separate from their neighbors in the set. Unfortunately, Kubernetes doesn’t provide a way to resize them from the StatefulSet object. The spec.resources.requests.storage property of the StatefulSet field is immutable, preventing you from applying any capacity increases you require. This article will show you how to workaround the problem.
Instructions
You can bypass the restriction by manually resizing the persistent volume claim (PVC). You'll then need to recreate the StatefulSet to release and rebind the volume from your Pods. This will trigger the actual volume resize event.
Find the
PVCsassociated with your StatefulSet withkubectl:
Use
kubectl editto enter in-cluster resource edit mode:
In opened editor find the
spec.resource.requests.storagefield and change it to your new desired capacity:
Save and close file. kubectl should report that the change has been applied to your cluster:
Repeat steps 2-4 for rest
PVCsfromStatefulSet(you need to edit all associated claims).Wait till Kubernetes update all claims. Check status with
kubectl:
Update
StatefulSetYAML manifest with new value (if you use GitOps tool like FluxCD you need to commit your changes).Delete
StatefulSetwith orphan cascading mechanism (its Pods remain in cluster) - this minimize downtime:
Apply
StatefulSetYAML manifest - the newStatefulSetwill assume ownership of the previously orphaned Pods.Perform rollout restart on StatefulSet: