How to resize a PVC

Created by Steve Place, Modified on Thu, Feb 13 at 4:13 PM by Steve Place

First, check what storage class your PVC is using:

> kubectl get pvc -n <namespace>
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
my-pvc Bound pvc-12345678-90ab-cdef-1234-567890abcdef 10Gi RWO longhorn 5d

In this example, our storage class is longhorn. We need to see if it can be resized. To do that, we'll run:

> kubectl get storageclass longhorn -o=jsonpath='{.allowVolumeExpansion}'

If this returns true, we're able to resize the PVC. If you see false or get no output, you can either choose a storage class that supports expansion (see your cloud provider's documentation for examples) or edit the storage class to allow expansion (covered in the Appendix).


Now that we have a PVC that supports expansion, we need to edit it:

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

Look for the spec.resources.requests.storage field and modify it to the desired size. For example, change:

spec:
resources:
requests:
storage: 10Gi

to:

spec:
resources:
requests:
storage: 20Gi

or whatever value you prefer. Save and exit the editor.


Now verify the change took effect:

> kubectl get pvc <pvc-name> -n <namespace>
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
my-pvc Bound pvc-12345678-90ab-cdef-1234-567890abcdef 20Gi RWO longhorn 5d

You can see that CAPACITY has be increased to 20Gi, which we were expecting. (Note it may take a few seconds to few minutes for the change to take effect.)


If the PVC is in the Pending status or the size hasn't changed, check for errors with:

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

After resizing, delete the Stardog pod using the PVC to force a restart. This ensures the Stardog pod will recognize the PVC's new capacity.

> kubectl delete pod <stardog-pod-name> -n <namespace>

Appendix


How to enable volume expansion in a storage class


The following steps show how to edit an existing storage class, but you can also use them to create a new storage class if you would prefer not to overwrite the old one.


You cannot edit a storage class directly in Kubernetes, so you'll need to delete and recreate it.


First export your current configuration to a YAML file:

> kubectl get storageclass longhorn -o yaml > longhorn-sc.yaml

In this example, the storage class is longhorn, but replace this with whatever your storage class is. Next, open your saved yaml file with a text editor and add/update the allowVolumeExpansion field:

allowVolumeExpansion: true

A correctly modified storage class YAML file will look something like this:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: longhorn
provisioner: driver.longhorn.io
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true

Since storage classes cannot be edited in place, you must delete the old one. Be careful - this won’t affect existing PVCs, but any new PVCs won’t have a storage class until you recreate it:

kubectl delete storageclass longhorn

Now recreate the storage class using our modified YAML file:

kubectl apply -f longhorn-sc.yaml

Finally, check to make sure our new class allows for volume expansion:

kubectl get storageclass longhorn -o=jsonpath='{.allowVolumeExpansion}'


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article