Skip to main content

Expanding Persistent Volumes created using StatefulSets

It is currently not possible to expand PVs created using a StatefulSet directly from the StatefulSet template.

This is the current work around -

Edit the ‘storage’ value under spec:resources for PVC required to be expanded:

kubectl edit pvc www-web-0
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi # edit with new value
  storageClassName: gp2
  volumeName: pvc-489b1857-91dd-11e9-b4c5-0a5b8815a91e

Once the edit has been applied, you should see type: Resizing under status:conditions:

kubectl get pvc www-web-0 -o yaml
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 4Gi
  conditions:
  - lastProbeTime: null
    lastTransitionTime: 2019-06-18T15:29:45Z
    status: "True"
    type: Resizing # You should see value
  phase: Bound

Delete the corresponding pod associated to the pv:

kubectl delete pod web-0
pod "web-0" deleted

Once pod is recreated, you should see the new pv disc size in the pvc

kubectl get pvc www-web-0 -o yaml
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 5Gi
  phase: Bound

The following command will delete the StatefulSet without deleting the associated pods

kubectl delete statefulset --cascade=false web # `web` is the name of the StatefulSet

Apply the StatefulSet template with new pvc size (with everything else exactly the same) to your namespace.

There is an open issue for expanding PVs using StatefulSet templates in github. Once this is implemented, the above workaround will no longer be required.

This page was last reviewed on 11 May 2021. It needs to be reviewed again on 11 August 2021 by the page owner #cloud-platform .
This page was set to be reviewed before 11 August 2021 by the page owner #cloud-platform. This might mean the content is out of date.