Hello, readers! In this article, we will be focusing on Kubernetes PV and PVC – Way to access Volumes in detail.
So, let us begin! 🙂
Table of Contents
What is Kubernetes Volume?
Volumes define the data storage space. That is, when we have data moving to cloud or any space we mean to say that we are provisioning space to store the data at runtime efficiently.
Kubernetes Volumes help us solve the problem of managing storage across the platform. When we have applications or units moving to cloud, the most prior and important provisioning resource that comes into picture is the storage. Because, when we have data in any form being uplifted and managed by any cloud platform or orchestrating tool, we too need to make sure that the underlying data being static or run-time needs to be in place intact.
In the course of this topic, we will be having a look at Kubernetes Persistent Volume (PV) and Persistent Volume Claim (PVC) to get space for the data being orchestrated through k8.
Let us go ahead with it.
1. Kubernetes Persistent Volumes (PV)
Kubernetes Persistent Volumes (PV) is actually a portion of storage that is available within the cluster. Yes, it is a storage block within the cluster and therefore it is a cluster level resource. The PV can be either provisioned to the user by the k8 administrator or can dynamically be provisioned through Storage Classes available in k8. These are independent of the pods and remain persistent even after the deletion of pod.
Going ahead, let us now look at the YAML structure that will enable us to provision a Persistent Volume for a user-
apiVersion: v1 kind: PersistentVolume metadata: name: demo-pv spec: storageClassName: "" capacity: storage: 10Gi accessModes: - ReadWriteOnce claimRef: name: demo-pvc namespace: demo
- As we are creating a PV, the kind would be PersistentVolume.
- Under the .metadata.name, we would place the name for the volume.
- The capacity, includes the storage space we need (10Gi in our case) and the accessModes which can be read and write once, read and write many, etc.
- We would then provide claimRef as it’s name and namespace name so that no other namespace or PVC can claim the above created PV. [Will be having a look at the concept of PVC in the next section]
Thus, we will now apply the PV to our desired namespace.
kubectl apply -f pv.yaml -n demo
Let us now describe the created Persistent volume.
kubectl describe pv demo-pv -n demo
Name: demo-pv Labels: <none> Annotations: <none> StorageClass: "" Status: Active Claim: Bound Message: Events: <none>
2. Accessing PV with Kubernetes PVC
Having understood PV in Kubernetes, let us understand how to access or claim it. Unless and until we do not claim it, a PV is just a piece of storage block in the cluster that is open for claims.
For the same, we need to bind the PV to our application.
By applying PV, we request the resource (PV) storage as a user. This can be assumed as a Pod because like a Pod, even a PVC consumes resources of PV.
Let us now have a look at the PVC YAML structure-
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: demo-claim namespace: demo spec: storageClassName: "" volumeName: demo-pv
With this YAML structure, one can understand that in PVC, we refer the Persistent Volume name as well as the namespace to set the boundaries and bind it to each other.
Let us now describe the PVC–
kubectl describe pvc demo-pvc Name: demo-pvc Namespace: demo StorageClass: "" Labels: <none> ...
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question.
For more such posts related to Kubernetes, Stay tuned with us.
Till then, Happy Learning! 🙂