Resize Persistent Volume in Kubernetes


You can only resize volumes containing a file system if the file system is XFS, Ext3, or Ext4. When a volume contains a file system, the file system is only resized when a new Pod is using the PersistentVolumeClaim in ReadWrite mode. File system expansion is either done when a Pod is starting up or when a Pod is running and the underlying file system supports online expansion.

First of all, the Storage Class must have the AllowVolumeExpansion: True configured:

AllowVolumeExpansion:  True

If it has not been setup yet, you can update it. For example

$ kubectl patch storageclass/"glusterfs" \
  --namespace "default" \
  --patch '{"allowVolumeExpansion": true}'

Then you need to edit or patch the current PVC config to reflect the new size. For example, I want to resize the glusterfs-test-pvc from 5G to 8G.

$ kubectl patch pvc/"glusterfs-test-pvc" \
 --namespace "default" \
 --patch '{"spec": {"resources": {"requests": {"storage": "8Gi"}}}}'

The full example:

$ kubectl describe sc glusterfs
Name: glusterfs
IsDefaultClass: Yes
Annotations: kubectl.kubernetes.io/last-applied-configuration={"allowVolumeExpansion":true,"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"glusterfs"},"parameters":{"resturl":"http://xxx.xxx.xxx.xxx:8080","volumetype":"none"},"provisioner":"kubernetes.io/glusterfs"}
,storageclass.kubernetes.io/is-default-class=true
Provisioner: kubernetes.io/glusterfs
Parameters: resturl=http://xxx.xxx.xxx.xxx:8080,volumetype=none
AllowVolumeExpansion: True
MountOptions: <none>
ReclaimPolicy: Delete
VolumeBindingMode: Immediate
Events: <none>
$ kubectl get pvc glusterfs-test-pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
glusterfs-test-pvc Bound pvc-45ed19f4-35e7-43a8-b4f2-e8e65d44a24a 5Gi RWO glusterfs 6d18h
$ kubectl get pv | grep glusterfs-test-pvc
pvc-45ed19f4-35e7-43a8-b4f2-e8e65d44a24a 5Gi RWO Delete Bound default/glusterfs-test-pvc glusterfs 6d18h
$ kubectl patch pvc/"glusterfs-test-pvc" –namespace "default" –patch '{"spec": {"resources": {"requests": {"storage": "8Gi"}}}}'
persistentvolumeclaim/glusterfs-test-pvc patched
$ kubectl get pvc glusterfs-test-pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
glusterfs-test-pvc Bound pvc-45ed19f4-35e7-43a8-b4f2-e8e65d44a24a 8Gi RWO glusterfs 6d18h
$ kubectl get pv | grep glusterfs-test-pvc
pvc-45ed19f4-35e7-43a8-b4f2-e8e65d44a24a 8Gi RWO Delete Bound default/glusterfs-test-pvc glusterfs 6d18h

Reference: https://kubernetes.io/blog/2018/07/12/resizing-persistent-volumes-using-kubernetes/
https://kubernetes.io/docs/concepts/storage/persistent-volumes/

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s