What are Kubernetes Persistent Volumes(PV), Persistent Volume Claims(PVC) and Storage Class?
Why are Persistent volumes needed?
Let’s assume you have deployed an application which needs to store its data in a MySQL database pod or even simply in the pod filesystem, and in case of a failure in this situation when a new pod is started all of the previous data is gone. Because Kubernetes doesn’t provide us with data persistence.
That brings the administrators to the need for configuring storage which is independent of pod lifecycle.
These are similar to a cluster resource like a node, CPU or RAM. It a piece of storage that is provisioned by the administrator or configured to be dynamically provisioned through a Storage class. The lifecycle of PVs is independent of the pod using the resource and also of namespaces.
PVs are the actual storage as external storage plugins to the cluster and administrators must decide where to provide them whether on a local server, NFS or any CSP storage like EBS, EFS, Azure File etc. Depending upon the amount of data to store, network latency, IOPS, high availability and cluster environment.
Persistent Volume Claims.
A PVC is nothing but a request from a pod to claim a PV, PVCs are mentioned in the YAML configuration file along with the amount of storage to be claimed and access mode. PVCs are similar to a pod, as pod consumes memory and cores, PVCs consume PV, as pods can demand a specific level of resources, so PVCs can demand specific size and access modes.
The dynamic provisioning feature eliminates the need for cluster administrators to pre-provision storage. Instead, StorageClass automatically provisions storage when it is requested by a user. A cluster administrator can define as many
StorageClass objects as needed, each specifying a volume plugin (aka provisioner) that provisions a volume.
In order to enable the dynamic provisioning, the administrator needs to pre-create a StorageClass object for users, the name of which must be a valid DNS subdomain name. One can go with any available storage depending upon the Cloud service provider:- AWS EBS, AzureFile to GCEPersistentDisk.