How to Resize a PVC for a StatefulSet

Quick howto for resizing a PVC for your StatefulSet

Find your PVC

❯ kubectl -n loki get pvc
NAME                                              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
eventhandler-cache-grafana-agent-eventhandler-0   Bound    pvc-5af27de9-ccf0-4e11-9b1d-6be8957be0cb   1Gi        RWO            standard-rwo   223d
storage-loki-0                                    Bound    pvc-e0b2cdcf-0926-484d-9cde-c5cfb54d0c50   20Gi       RWO            standard-rwo   293d

In our case, we will resize storage-loki-0.

Be sure that the StorageClass used allows the volume expansion (see doc).

Patch the PVC

We want to upgrade storage-loki-0 to 50Gi.

❯ kubectl -n loki patch pvc storage-loki-0 -p '{ "spec": { "resources": { "requests": { "storage": "50Gi" }}}}'

Wait a bit until the volume size has been increased.

Take a look at kubect get events.

Find your StatefulSet

❯ kubectl -n loki get sts
NAME                         READY   AGE
grafana-agent-eventhandler   1/1     243d
loki                         1/1     189d

Delete the StatefulSet

❯ kubectl -n loki delete sts loki --cascade=orphan

Now your issue is fixed.