In this tutorial, we are going to guide you with a simple example of setting up a Persistent Volume (PV) on your OVHcloud Managed Kubernetes Service.
You will create a Persistent Volume Claim
(PVC), that will automatically create a Persistent Volume
(PV) that creates an associated Public Cloud Block Storage volume.
Then you will create a Pod
attached to the PVC.
Before you begin
This tutorial assumes that you already have a working OVHcloud Managed Kubernetes cluster and some basic knowledge of how to operate it. If you want to learn more about these topics, please look at the OVHcloud Managed Kubernetes Service Quickstart.
It also assumes that you have read our Persistent Volumes on OVHcloud Managed Kubernetes guide.
Persistent Volumes (PV) and Persistent Volume Claims (PVC)
As the official documentation states:
- A
PersistentVolume
(PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. It is a resource in the cluster just like a node is a cluster resource. - A
PersistentVolumeClaim
(PVC) is a request for storage by a user. It is similar to a pod. Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., they can be mounted once read/write or many times read-only).
Or, if you prefer an analogy, PVCs are to PVs as pods are to nodes.
PVCs consume abstract storage resources (the PVs) as Pods consume node resources.
So you want some persistent storage on your cluster
Let’s say you need some persistent storage on your cluster (i.e., some kind of network storage for OVHcloud Managed Kubernetes Service). That currently means storage based on Cinder. In Kubernetes terms, you will need two objects: a PersistentVolumeClaim
and its associated PersistentVolume
.
How do you get them? Just create the PVC object in your cluster. Kubernetes will see your claim and, according to its available resources, allocate a PV corresponding to your claim.
Let’s create a PVC
Copy the next YAML fragment into a test-pvc.yaml
file:
And apply it to your cluster:
Then you can see the PVC and the associated PV using kubectl
:
Example:
Using the PVC
Pods access storage by using the PVC as a volume. In the pod manifest, you declare a volume and associate it to a PVC. The volume is then mounted to the host and into the pod.
For our example, let's create a test-pvc-pod.yaml
file: that deploys a simple Nginx server using our test-pvc
PVC as external volume:
Apply it to the cluster:
Check that everything is working correctly:
You should obtain a result like this:
Storage Classes
We currently support two Storage Classes on OVHcloud Managed Kubernetes:
-
csi-cinder-high-speed-gen2
storage class is based on hardware that includes SSD disks with NVMe interfaces. The performance allocation is progressive and linear (30 IOPS allocated per GB and 0.5MB/s allocated per GB) with a maximum of 20k IOPS and 1GB/s per volume. The IOPS and bandwidth performance will increase as scale up the storage space. -
csi-cinder-high-speed
performance is fixed. You will get up to 3,000 IOPS per volume, regardless of the volume size. -
csi-cinder-classic
uses traditional spinning disks (200 IOPS guaranteed, Up to 64 MB/s per volume).
All these Storage Classes
are based on Cinder, the OpenStack block storage service. The difference between them is the associated physical storage device. They are distributed transparently, on three physical local replicas.
High Speed performance is theoretically best for volumes up to 100GB. Above 100GB per volume, you will get enhanced performance with a High Speed Gen2 volume.
Example:
When you create a Persistent Volume Claim on your Kubernetes cluster, we provision the Cinder storage into your account. This storage is charged according to the OVH flexible cloud storage prices.
Since Kubernetes 1.11, support for expanding Persistent Volume Claims (PVCs) is enabled by default, and it works on Cinder volumes. To learn how to resize them, please refer to the Resizing Persistent Volumes tutorial. Kubernetes PVCs resizing only allows to expand volumes, not to decrease them.
Access Modes
The way a PV can be mounted on a host depends on the capabilities of the resource provider. Each PV gets its own set of access modes describing that specific PV’s capabilities:
-
ReadWriteOnce
: the PV can be mounted as read-write by a single node -
ReadOnlyMany
: the PV can be mounted read-only by many nodes -
ReadWriteMany
: the PV can be mounted as read-write by many nodes
Our storage resource, Cinder, doesn’t allow to mount a PV on several nodes at the same time, so you need to use the ReadWriteOnce
access mode.
Reclaim policies
When you are done with a volume, you can delete the PVC, to liberate the resource. At that instant you have an unbounded PV object on your cluster, and its fate depends on the reclaim policy you have chosen in your PVC.
There are two possible reclaim policies:
-
Retain
: When the PVC is deleted, the PV still exists. The volume is considered released, but it is not yet available because the previous data remains on the volume. If you want to delete it, you must do it manually. -
Delete
: when the PVC is deleted, the PV and the associated storage in the external infrastructure (i.e. the Cinder storage in our case) are both deleted.
For every Storage Class there is a reclaim policy set by default, that can be changed for individual instances of PV. On our Cinder based storage classes, the reclaim policy by default is Delete
, as you can verify:
Example:
Delete a PVC (and associated PV)
Thanks to the Delete
reclaim policy, if you delete the PVC, the associated PV is also deleted:
Example:
Changing the reclaim policy
To illustrate how to change the reclaim policy, let's begin by creating a new PVC using the test-pvc.yaml
file:
List the PV and get its name:
And patch it to change its reclaim policy, where <your-pv-name>
is the name of your chosen PersistentVolume.:
Now you can verify that the PV has the right policy:
Example:
In the preceding output, you can see that the volume bound to PVC default/test-pvc
has reclaim policy Retain
.
It will not be automatically deleted when a user deletes PVC default/test-pvc
.
Go further
For more information and tutorials, please see our other Managed Kubernetes support guides or explore the guides for other OVHcloud products and services.
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.