Persistent Volume in Kubernetes
Volumes were great as they saves us from data lost just in case of container restart.
Volumes hold data at a pod level but question could also be asked what if for any reason Kubernetes terminates the pod e.g rescheduling the pod.
within the case of pod termination data within the volumes are going to be lost.
to unravel this issue Kubernetes provides us option for Persistent Volume.
Persistent Volume put a volume at a cluster level instead pod level.
We create a Persistent Volume resource during which we provide cluster level volume which will be employed by any pod.
The pod may use that Persistent Volume by using another resource Persistent Volume claims.
It always available outside of the pod life cycle.
meaning volume will remain even after the pod is deleted.
This volume are going to be available to say by another pod if required, and therefore the data is retained.
POD → Persistent Volume claim → Persistent Volume
Persistent Volume Claim
The persistent volume claim explains the quantity and characteristics of the storage required by the pod.
supported requirement from user PVC finds any matching Persistent Volumes and claims it.
counting on the configuration options used for Persistent Volume resource, these PV resource can later be used/claim by other pods.
Understanding Persistent Volume Specs
sorts of access Modes
ReadWriteOnce (Only one node can mount the quantity for reading and writing)
ReadOnlyMany (Multiple nodes can mount the quantity for reading)
ReadWriteMany (Multiple nodes can mount the quantity for both reading and writing)
RWO,ROX, and RWX pertain to the amount of worker nodes which will use the quantity at an equivalent time, to not the amount of pods !
Persistent Volume Reclaim Policy
We’ve learned that counting on the configuration options used for Persistent Volume resource, these PV resource can later be used/claim by other pods.
The lifetime of a Persistent Volume is decided by its reclaim policy.
The Reclaim policy took care the action the cluster would take when a pod releases its ownership of the storage.
Persistent Volume Reclaim Policy tag are often utilized in YAML configuration file at the time of making PV.
Reclaim Policy are often set to
Delete (Persistent Volume are going to be deleted when the PVC is deleted but data will persist)
Recycle (Volume’s content are going to be deleted,persistent volume are going to be available to be claimed again)
If persistent volume Reclaim Policy not described, Retain is default.
Kubernetes will retain the quantity and its contents after it’s released from its claim.
To form persistent volume available again for claims are often done by delete and recreate the persistent volume resource manually.
Underlying storage can either delete of left to be reused by subsequent pod.