Bobcares

OVH Kubernetes Persistent Volume | Guide

by | Nov 16, 2023

Learn how to set up Persistent Volume on OVH Kubernetes. Our Kubernetes Support team is here to help you with your questions and concerns.

OVH Kubernetes Persistent Volume | Guide

A persistent volume can be described as a piece of storage set aside by an administrator in a cluster.

In other words, it is a resource in the cluster. Furthermore, the persistent volume is a volume plug-in with a lifecycle that is not dependent on any individual pod using the persistent volume.

PVs have different access modes that define how the storage can be accessed. These include:

  • ReadWriteOnce

    It is mounted as read-write by a single node.

  • ReadOnlyMany

    It can be mounted as read-only by several nodes.

  • ReadWriteMany

    Then it can be mounted as read-write by several nodes.

Storage Classes help dynamically allot persistent volumes according to users’ needs. Furthermore, OVH Kubernetes supports storage classes that define different classes of storage with specific features and performance characteristics.

Upon creating a Persistent Volume resource in a Managed Kubernetes cluster, the system automatically generates a corresponding Public Cloud Block Storage volume.

Furthermore, Kubernetes Volumes exist only during the Pod’s lifetime.Deleting the pods results in the automatic deletion of the volumes. Hence, Kubernetes Volumes are useful for storing temporary data.

Additionally, Kubernetes Persistent Volumes (PV) lets us work with non-volatile data in Kubernetes. Persistent volumes remain independent of a single pod or the pod lifecycle. In fact, Pods can claim PersistentVolumes. This gives them access to the data.

The most common application for PV in Kubernetes is databases. Persistent Volumes are essential in Kubernetes to deploy database data persistently, unbound to a particular pod.

Let’s take a look at how to deploy a database in Kubernetes:

  1. To begin with, create and configure a Pod for the database engine.
  2. Then, attach a PV to the pod with a PersistentVolumeClaim.
  3. We have to mount the claimed volume to the Pod.

As seen in the above steps, we have to create a PVC ( Persistent Volume Claim) to use a Persistent Volume on a Kubernetes cluster.

Persistent Volume Claims are requests to set up a Persistent Volume of a certain type and configuration.

Furthermore, cluster admins define different kinds of persistent storage, using Storage Classes.

When we need a Persistent Volume, you have to create a Persistent Volume Claim and choose a Storage Class from the available options offered by the cluster administrators.

The Storage Class allocates an actual infrastructure volume storage device to our account, followed by the creation of a Persistent Volume on the physical device.

OVH Kubernetes Persistent Volume

 

PersistentVolumes on OVHcloud Managed Kubernetes

OVHCloud supports several Storage Classes on OVHcloud Managed Kubernetes as seen here:

  • csi-cinder-classic
  • csi-cinder-high-speed

We can easily display them with this command:

$ kubectl get storageclassCopy Code

Furthermore, the storage classes are based on Cinder. It is an OpenStack Block Storage service.

The difference between csi-cinder-classic and csi-cinder-high-speed is the physical storage device. While the latter uses SSD, the former uses traditional spinning disks.

Still, they transparently distribute on three physical local replicas.

When we create a PVC on our Kubernetes cluster, OVHCloud allots the Cinder storage into our account. Our experts would like to point out that the charges for the storage will be as per the OVH Flexible Cloud Block Storage Policy.

Furthermore, Kubernetes offers support for PVCs by default since 1.11. Also, it works on Cinder volumes. Although Kubernetes PVCs resizing lets us expand volumes, it does not let us reduce them.

How to set up a PersistentVolume

Today, your experts are going to take us through a simple example as seen here:

How to set up a PersistentVolume

  1. To begin with, we have to create a namespace as seen here:
    kubectl create ns nginx-exampleCopy Code
  2. Then, we have to define a PVC in a file named pvc.yaml with this content:
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: nginx-logs
    namespace: nginx-example
    labels:
    app: nginx
    spec:
    storageClassName: csi-cinder-high-speed
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 1Gi
    Copy Code
  3. Now, it is time to apply the YAML manifest as seen here:
    kubectl apply -f pvc.yamlCopy Code
  4. At this point, we can check if the new PVC and PV has been created:
    kubectl get pvc -n nginx-example
    kubectl get pvCopy Code

    Once we run the above commands we will see the following output:

    $ kubectl get pvc -n nginx-example
    NAME         STATUS   VOLUME                                                                   CAPACITY   ACCESS MODES   STORAGECLASS            AGE
    nginx-logs   Bound    ovh-managed-kubernetes-d6r47l-pvc-a6025a24-c572-4c28-b5e7-c6f8311aa47f   1Gi        RWO            csi-cinder-high-speed   21s
    Copy Code
    
    $ kubectl get pv
    NAME                                                                     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                      STORAGECLASS            REASON   AGE
    ovh-managed-kubernetes-d6r47l-pvc-a6025a24-c572-4c28-b5e7-c6f8311aa47f   1Gi        RWO            Delete           Bound    nginx-example/nginx-logs   csi-cinder-high-speed            19s
    Copy Code

    Here, we can see that the PV is created and is Bound to the PVC we created.

  5. Then, create a file named deployment.yaml with this content:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: nginx-deployment
    namespace: nginx-example
    spec:
    strategy:
    type: Recreate
    replicas: 1
    selector:
    matchLabels:
    app: nginx
    template:
    metadata:
    labels:
    app: nginx
    spec:
    volumes:
    - name: nginx-logs
    persistentVolumeClaim:
    claimName: nginx-logs
    containers:
    - image: nginx:1.7.9
    name: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - mountPath: "/var/log/nginx"
    name: nginx-logs
    readOnly: false
    Copy Code
  6. Now apply it with this command:
    kubectl apply -f deployment.yamlCopy Code
  7. Then, create a service for the Nginx container in a file named svc.yaml:
    
    apiVersion: v1
    kind: Service
    metadata:
    labels:
    app: nginx
    name: nginx-service
    namespace: nginx-example
    spec:
    ports:
    - port: 80
    targetPort: 80
    selector:
    app: nginx
    type: LoadBalancer
    Copy Code
  8. Now apply it as seen here:
    kubectl apply -f svc.ymlCopy Code
  9. Then, we have to wait til we get an external IP:
    kubectl -n nginx-example get svc/nginx-service -wCopy Code
  10. Now, it is time to perform some calls to the URL so that we can generate some access logs:
    export NGINX_URL=$(kubectl get svc nginx-service -n nginx-example -o jsonpath='{.status.loadBalancer.ingress[].ip}')
    echo Nginx URL: http://$NGINX_URL/Copy Code

    curl -I http://$NGINX_URL/

  11. Now, we have to connect to the pod to read the log files. So, run this command to get the name of the Nginx running pod:
    export POD_NAME=$(kubectl get po -n nginx-example -o name)Copy Code
  12. Then once we connect to it we can see our access logs:
    kubectl -n nginx-example exec $POD_NAME -c nginx -- cat /var/log/nginx/access.logCopy Code

PV Lifecycle and Reclaim Policy

Now, let’s take a look at the Reclaim Policy:

The persistentVolumeReclaimPolicy field in the PV definition decides the future of the volume. There are three options, namely, “Retain,” “Delete,” or “Recycle.”

Additionally, OVH Kubernetes supports dynamic provisioning. Here, claiming a PVC prompts the automatic creation of PVs in this instance.. Furthermore, the storage class decided the type of storage to allot.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to set up Persistent Volume on OVH Kubernetes.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!