In Kubernetes (k8s), a Persistent Volume (PV) is a cluster-wide piece of storage in the cluster that has a lifecycle independent of any individual pod that uses the PV. It serves as a way to decouple the definition of storage from the pod using it. Persistent Volumes are resources in the cluster just like nodes and can be dynamically provisioned or pre-provisioned by an administrator.
Here are some key concepts related to Persistent Volumes in Kubernetes:
- Storage Classes:Kubernetes provides a concept called "Storage Classes" which are used to define different classes of storage with different performance characteristics.Storage Classes are used by Persistent Volume Claims (PVCs) to request dynamic provisioning of Persistent Volumes.
- Persistent Volume Claims (PVCs):A Persistent Volume Claim is a request for storage by a user.When a user creates a PVC, it requests storage with specific requirements (e.g., size, access mode) using a Storage Class.If a suitable Persistent Volume is available, it is bound to the claim. If not, and dynamic provisioning is enabled, a new Persistent Volume may be dynamically provisioned.
- Access Modes:Persistent Volumes have access modes that define how the storage can be accessed by pods. The three common access modes are ReadWriteOnce, ReadOnlyMany, and ReadWriteMany.ReadWriteOnce: The volume can be mounted as read-write by a single node.ReadOnlyMany: The volume can be mounted as read-only by many nodes.ReadWriteMany: The volume can be mounted as read-write by many nodes.
- Reclaim Policies:When a Persistent Volume is released (i.e., the associated claim is deleted), the data on the volume can be retained or deleted based on the reclaim policy.The two common reclaim policies are Retain and Delete.Retain: The volume is not automatically deleted. It is the responsibility of the administrator to manually reclaim the resources.Delete: The volume is automatically deleted when the associated claim is deleted.
- Dynamic Provisioning:Dynamic provisioning is a feature in Kubernetes that allows storage volumes to be automatically provisioned when a PVC is created.The storage class specifies the provisioner, which is responsible for creating the volume. This allows for on-demand creation of volumes based on the storage class definition.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
storage: 5Gi