Learn how to resize Persistent Volumes (PVs) on your OVHcloud Managed Kubernetes Service.
The Kubernetes PersistentVolume subsystem provides an API for users and administrators that abstracts details of how storage is provided from how it is consumed. To do this, Kubernetes provides two API resources: PersistentVolume (PVs) and PersistentVolumeClaim (PVCs).
Since Kubernetes 1.11, support for expanding PersistentVolumeClaims (PVCs) is enabled by default, and in this tutorial, you will learn how to do it.
NOTE: Kubernetes PVCs resizing only allows expanding volumes, not decreasing them.
Volume resizing works with all storage classes, including LUKS-encrypted volumes (csi-cinder-high-speed-luks, csi-cinder-classic-luks, csi-cinder-high-speed-gen2-luks). The encryption is transparently maintained during the resize operation.
Before you begin
This tutorial presupposes that you already have a working OVHcloud Managed Kubernetes cluster and some basic knowledge of how to operate it. If you want to know more about those topics, please look at the deploying a Hello World application documentation.
You also need to know how PVs are handled on OVHcloud Managed Kubernetes service. Please refer to the Persistent Volumes on OVHcloud Managed Kubernetes guide.
NOTE: When a Persistent Volumes resource is created inside a Managed Kubernetes cluster, an associated Public Cloud Block Storage volume is automatically created with it. This volume is hourly charged and will appear in your Public Cloud project. For more information, please refer to our Volume Block Storage pricing page.
Instructions
Let’s make a Persistent Volume Claim
To test the PV resizing, we will need a PV associated with the cluster, i.e., we need to deploy a service making a PVC. To keep things simple, we choose to deploy a single instance of MySQL.
Let’s begin by creating a mysql-pvc.yaml to define an initial PVC with 2 GB of allocated space:
And apply it to the cluster:
We can then verify that the PVC is correctly created and bound to a PV:
Now we create a mysql-deployment.yaml file to deploy MySQL using that PVC:
And we deploy and verify it:
In my example cluster, the preceding commands obtain:
Accessing the MySQL instance and initializing a database
The preceding YAML file creates a service that allows other Pods in the cluster to access the database. The Service option clusterIP: None lets the Service DNS name resolve directly to the Pod’s IP address. This is optimal when you have only one Pod behind a Service, and you don’t intend to increase the number of Pods.
Now we are going to use kubectl to create a mysql client on the fly to connect to the database:
And then simply create a database with a table:
On my example cluster:
Expand the PVs
To expand the persistent volume, the first step is to unbind the PVC from the deployments using it. To do that, we set the deployment’s replicas to 0:
NOTE: Do not forget to downscale your deployment before resizing your volume
Then we path the PVC definition to expand the volume to 6 GB:
NOTE: Kubernetes PVCs resizing only allows to expand volumes, not to decrease them. If you try to decrease the storage size, you will get a message like
We verify that the volume has been expanded:
In the “conditions” field shown by the output of the previous command line, we can see that the PVC is waiting for the user to start a pod to finish the file system resize of the volume. Let’s put replicas back to 1 on mysql-deployment.yaml, and deploy it again to start a pod:
After the pod starts, we can use again kubectl describe pvc mysql-pv-claim and we see that the PV size is 6 GB.
On my example cluster:
Verifying data integrity
So we launch again a MySQL client to verify that we can still read our database:
A SHOW DATABASES; should allow us to see our testingResize database, we can select it and find our anEmptyTable table.
On my example cluster:
Go further
For more information and tutorials, please see our other Managed Kubernetes or Platform as a Service guides. You can also explore the guides for other OVHcloud products and services.