Kubernetes Persistent Volumes
A PersistentVolume (PV) is a piece of storage in a Kubernetes cluster, provisioned by an administrator or dynamically provisioned using a Storage Class. Its lifecycle is independent of any individual Pod that uses it.
How to Manually Create a PV
Below is the manifest for manually creating a PV.
1 | apiVersion: v1 |
storageClassName: The name of the StorageClass. Once a PV has this field set, it can only be bound by a PVC that requests that same StorageClass name. If not specified, it can be bound by any StorageClass.
capacity: The storage capacity of the PV. Currently only specifying storage size is supported.
accessModes: The access modes of the PV. Supported modes are ReadWriteOnce (RWO), ReadOnlyMany (ROX), and ReadWriteMany (RWX). A volume in a Pod can only use one access mode at a time, even if the PV supports multiple modes.
persistentVolumeReclaimPolicy: The reclaim policy for the PV. Supported policies are Retain (default for manually created PersistentVolumes), Delete (default for dynamically provisioned PersistentVolumes), and Recycle (deprecated).
Create
1 | kubectl apply -f https://raw.githubusercontent.com/chengqing-su/kubernetes-learning/master/volumes/pv.yaml |
Running kubectl get pv task-pv-volume -o yaml produces the following output:
1 | apiVersion: v1 |
PV Phases
In the output above, status.phase indicates the current phase of the PV. The possible phases are:
Available: The PV has not yet been bound to a PersistentVolumeClaim (PVC).
Bound: The PV has been bound to a PersistentVolumeClaim (PVC).
Released: The PersistentVolumeClaim (PVC) that was bound to this PV has been deleted, but the resources associated with the PV have not yet been reclaimed.
Failed: The PV has failed its automatic reclamation.