Persistent Volumes and Persistent Volume Claims

Anh Trần Tuấn - Aug 18 - - Dev Community

Source: Persistent Volumes and Persistent Volume Claims

1. Persistent Volumes (PVs)

A Persistent Volume (PV) is a cluster-level resource in Kubernetes representing a piece of storage that has been provisioned for use by one or more Pods. PVs are not tied to the lifecycle of individual Pods, ensuring data persistence even if Pods are rescheduled or deleted.

Key characteristics of Persistent Volumes:

         + Independent of Pods: This means that even if you delete a Pod that was using a PV, the data in the PV will remain intact. This is crucial for applications that require long-term data storage, such as databases or data analysis tools.

         + Persistent Storage: PVs can be backed by different storage systems, giving you the flexibility to choose the best storage solution for your specific needs. For example, you might use SSDs for high-performance applications and HDDs for large-scale data storage.

         + Lifecycle Management: These policies allow you to control how PVs are managed over time. For example, you can set a retention policy to automatically delete data after a certain period, or you can set a reclaim policy to automatically release the PV when it is no longer in use.

Create a Persistent Volume

apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
nfs:
path: /path/to/nfs
server: nfs-server.example.com
storageClassName: manual
accessModes:
- ReadWriteMany

2. Persistent Volume Claims (PVCs)

A Persistent Volume Claim (PVC) is a Kubernetes object that represents a request for storage. It's like a user or application submitting a ticket to a storage administrator, specifying the amount of storage needed, how it should be accessed (read-only, read-write, etc.), and what type of storage is preferred (e.g., SSD, HDD).

Think of it as a contract between the application and the underlying storage system. The PVC defines the application's storage needs, and Kubernetes is responsible for matching the PVC to an available Persistent Volume (PV) that meets the specified requirements.

Key Characteristics of Persistent Volume Claims:

         + Size and Access Modes: PVCs can specify a certain amount of storage and access modes (ReadWriteOnce, ReadOnlyMany, ReadWriteMany).

         + Automatic Provisioning: Kubernetes will automatically provision PVCs with suitable PVs based on the PVC's requests and the PV's attributes.

         + Abstraction: PVCs allow applications to request storage without knowing the details of how the storage is provided.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: manual

3. Using Persistent Volumes and Persistent Volume Claims


Step 1: Create a Persistent Volume

Read more at : Persistent Volumes and Persistent Volume Claims

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player