Resizing Persistent Volumes in Kubernetes

by | Jul 12, 2022

You want to resize a PersistentVolume (PV) in Kubernetes? In this tutorial, you’ll learn how to do it. If you don’t already know what a PV is and how you can create one, you should check out the tutorial Creating Persistent Volumes in Kubernetes first.

 

Let’s resize

Resizing a PV is not a big deal. Make sure that you edit the PersistentVolumeClaim and NOT the PersistentVolume object. The PVC object can be edited with the command kubectl edit. If you have gone through the tutorial mentioned before, you have a PVC object in your cluster which name is nginx-documentroot. We will increase the size of the corresponding volume from 1 GiB to 5 GiB by editing the PVC object:

$ kubectl edit pvc nginx-documentroot

Your default editor will be opened and it will show the yaml-representation of the PVC object. You can now change the volume size under .spec.resources.requests.storage.

 

After saving and exiting the editor, the volume resize takes place. The default StorageClass (Cinder) in NWS Managed Kubernetes clusters supports Online Expansion, i.e. the filesystem on the volume is resized, if it is mounted to a running pod. This means you don’t have to restart your pods to make the extra storage available to your container applications. Note that decreasing the size of an existing volume is not possible. The Kubernetes-API doesn’t even allow it.

To make sure that the resize was successful, you can take a look at the PVC and the PV objects:

 

The PV was updated so that both objects now show the capacity of 5 GiB. To be completely sure that the resize worked you can kubectl exec into the container that mounts the PV:

 

Further helpful information

This little tutorial showed you how to resize PersistentVolumes. But how do you know when it’s time to do a resize? The Kube Prometheus Stack is a great tool to monitor the disk usage of all the PVs in your cluster. If you want to get notifications as soon as the disk usage on a volume exceeds a certain limit, you might find the tutorial Kubernetes Alerting with Prometheus Alertmanager helpful.

More about Kubernetes
Custom Connection Limit for Load Balancers

Custom Connection Limit for Load Balancers

You need to set a custom limit for incoming connections on your load balancer? Here you can learn how to achieve this! About the Connection Limit The connection limit specifies the maximum allowed number of connections per second for a load balancer listener (open...

Automatic Fedora CoreOS Updates for your Kubernetes

Automatic Fedora CoreOS Updates for your Kubernetes

You want automated Fedora CoresOS updates for your Kubernetes? And what do Zincati and libostree have to do with it? Here you will quickly see an overview! Fedora CoreOS is used as the operating system for many Kubernetes clusters. This operating system, which...

X-Forwarded-For and Proxy-Protocol

X-Forwarded-For and Proxy-Protocol

You want to know how to get the IP addresses of your clients in your Kubernetes cluster? In five minutes you have an overview! From HTTP client to application In the nginx-Ingress-Controller tutorial, we showed how to make an application publicly accessible. In the...