Jul 12, 2022 | Kubernetes, Tutorials

Resizing Persistent Volumes in Kubernetes

by

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.

Subcribe for next article

More articles in Kubernetes | Tutorials
LUKS Encrypted Storage on Kubernetes

LUKS Encrypted Storage on Kubernetes

More and more stateful workloads are making their way into production Kubernetes clusters these days. Thus, chances are that you're already using persistent volumes or persistent volume claims (PVs/PVCs) in lieu with your deployed workloads. If you want to thoroughly...

Comparing Kubernetes Deployment Tools – What We Got Today

Comparing Kubernetes Deployment Tools – What We Got Today

Imagine your company embraced a microservice architecture. As you develop and deploy more and more microservices, you decide to orchestrate them using Kubernetes. You start writing YAML manifests and additional configuration, and deploy necessary tooling to your...

Introducing the NWS Kubernetes Playground

Introducing the NWS Kubernetes Playground

We are thrilled to introduce our brand-new NWS Kubernetes Playground! This interactive platform is designed to help you master cloud-native technologies, build confidence with tools like Kubernetes, and explore a range of NWS offerings – All for free!   What is...

LUKS Encrypted Storage on OpenStack

LUKS Encrypted Storage on OpenStack

Thoroughly securing your IT landscape has become more and more important over the last couple of years. With an increase in (user) data to be managed, processed, and stored, encryption of this data should be on your agenda towards fully secured IT infrastructure....

Securing ingress-nginx with cert-manager

Securing ingress-nginx with cert-manager

In one of our first tutorials, we showed you how to get started with ingress-nginx on your Kubernetes cluster. As a next step, we will tell you how to go about securing ingress-nginx with cert-manager by creating TLS certificates for your services! What is...

Migrating Servers from VMware to Openstack

Migrating Servers from VMware to Openstack

In this tutorial, we will have a look at migrating servers from VMware to OpenStack. After VMware's recent acquisition by Broadcom, many Cloud Service Providers (CSPs) face termination of their partnership programs with VMware. With no further information publicly...

Upgrading Ubuntu: From 20.04 to 22.04 with Nextcloud 26 and PHP 8.1

Upgrading Ubuntu: From 20.04 to 22.04 with Nextcloud 26 and PHP 8.1

Every couple of years Ubuntu brings out a new LTS version of its operating system and with it comes a bundle of new applications and dependencies. This can be both exciting and challenging for sys-admins who need to make everything work after an upgrade. One of the...

Mastering Kubernetes with Cilium: Empowering L7 Traffic Control

Mastering Kubernetes with Cilium: Empowering L7 Traffic Control

With the new release of the Cilium CNI on our Kubernetes Service you'll get the ability to filter traffic based on L7 properties. It's very powerful and can help a lot with your services security. In this tutorial, we'll be securing an API endpoint to allow access...

Using Terraform with OpenStack

Using Terraform with OpenStack

Many of you may already be familiar using Terraform with Azure or AWS. Although these may be the most used platforms, there is still a need for variety of other options due to local regulations (GDPR). As our systems are geared towards Open-Source, we will be looking...

Dynamic Inventory – An Ansible and Openstack Lovestory

Dynamic Inventory – An Ansible and Openstack Lovestory

For those of you that may not be too familiar with Ansible, it is a great tool to get started in the world of automation and making your life with configuration management a whole lot easier. In this tutorial we will be going through a basic playbook that you can use...