6.5 C
London
Sunday, December 22, 2024

Persistent Volumes in Kubernetes

Persistent volumes (PVs) provide a higher abstraction than simple volume objects. They decouple storage from the pods that use them, enabling Kubernetes to remount them into new pods after the pod’s deletion or restarting.

PVs are implemented via the Container Storage Interface (CSI), a plugin system that allows storage implementations to be standardized. You can add CSI-enabled storage to Kubernetes clusters using the kubectl command.

Data Storage

A persistent volume, also known as a PV, is a cluster resource that stores data on a local disk, cloud storage, or network share and has its life cycle independent of any pods using it. Persistent volumes expose object, file, and block storage systems via API objects that capture the implementation details of NFS, Ceph, or iSCSI and provide stateful applications with access to this storage throughout the application lifecycle.

When a container needs storage for its data, it requests it through a Persistent volume claim (PVC). The PVC specifies the amount of storage it needs and access modes.

The Kubernetes master binds these PVCs with Persistent Volumes (PVs) that match the PVCs’ storage class, access modes, and requested storage size. If no PV fits a given PVC, the control loop dynamically creates one and binds it to the PVC.

Bindings are based on a claim containing the PV’s name, storage class, and access modes. The control plane iterates over the group of all PVs with matching ways, determining which ones can check the claimed PV’s method and size, then binds these to the claim.

When a PVC is deleted, it must be handled according to the reclaim policy defined by its storage class. Reclaim policies allow the cluster to either retain it for manual reclamation or recycle it back into the pool of available volumes.

Log Storage

Applications may quickly request and use storage resources with the help of Kubernetes persistent volumes (PV). PVs are defined by Persistent Volume Claims API objects that represent a request for specific quantities of storage capacity.

Each PV has a specification or spec that defines the resource’s capabilities. It contains information about the resource, such as storage capacity, access modes, and plugin types.

The spec also describes the lifecycle of the resource. The reclaim policy of a persistent volume tells the cluster what to do with the help after it is released from its claim.

When a PVC is deleted, the previous claimant’s data remains on the volume and must be handled according to policy. The reclaim policy can be Retained, Recycled, or Delete.

A persistent volume can be manually or dynamically provisioned through a storage class. It creates a default storage class for you, but you can use a different one if needed.

Once a storage class is specified, it allows the control plane to provision PVs automatically to meet the requirements of your PVCs. For example, when a PVC requests a certain amount of storage and access mode, the control plane finds a matching PV and binds it together.

The volume binding mode for a persistent volume can be Immediate, WaitForFirstConsumer, or ReadWriteOnce. This mode is essential for determining when PVs are bound and how much storage a user can receive.

Database Storage

Businesses use databases to store information in a structured, organized way for easy access and management. This data can be personal data from online stores, inventory and orders from an e-commerce store, or any other type of business data that needs to be stored in one consolidated location for a specific purpose.

Traditionally, a database is stored in a flat file structure on disk. But that only works well for applications that must keep millions of files written and updated in real-time.

So Kubernetes provides Persistent Volumes (PVs) to enable the storage of databases on a cluster. PVs are created statically or dynamically by a cluster administrator.

Dynamic provisioning is enabled by PersistentVolumeClaims that request a specific storage class. If none of the static PVs the administrator creates match the PersistentVolumeClaim, the cluster dynamically attempts to provide a volume, especially for the PVC.

For example, it may be dynamically provisioned when the PersistentVolumeClaim specifies a StorageClassName that matches one of those volumes. If the PersistentVolumeClaim doesn’t define a StorageClassName, the cluster uses its default StorageClass.

When a PersistentVolumeClaim is bound to a PV, the user owns the volume for as long as their Pods use it. For this reason, a PVC that is in active use by a Pod or deleted by an admin will not be removed until its binding is released.

Storage Beyond the Lifecycle of a Pod

Persistent volumes (PVs) are administrator-provided storage with a specific file system, size, and identifying characteristics such as volume ID and name. They provide a consistent storage environment for application containers in Kubernetes.

PVs are backed by storage classes that interface with different kinds of local disks, cloud storage, or network share. These implementation details are kept separate from how pods use the warehouse, ensuring high availability in the infrastructure.

When a pod requests storage, it issues a persistent volume claim (PVC). PVCs describe the storage capacity and characteristics that a pod needs. The cluster attempts to match the request with a PV that meets those requirements.

A PV bound to a PVC can be deleted or retained depending on the policy. The first option, retain, keeps the bound PV from being used by a new PVC. The second option, delete, completely removes the bound PV together with the PVC.

In either case, the data on the PV is only recoverable if there are separate backups. If the bound PV is deleted, any associated storage asset in external infrastructure.

For all these reasons, it makes sense to use persistent volumes for storage beyond the lifecycle of a pod. This allows you to protect critical data, manage it independently of pods, and ensure data continuity without a single point of failure in your Kubernetes cluster.

Latest articles

Related articles