Hello and welcome to this lecture on Persistent Volumes in Kubernetes. In the previous lecture.
We created a persistent volume.
Now we will create a Persistent Volume Claim to make the storage available to a node. Persistent
Volumes and Persistent Volume Claims are two separate objects in the Kubernetes namespace.
An Administrator creates a set of Persistent Volumes and a user creates Persistent Volume Claims to
use to storage.
Once the Persistent Volume Claims are created, Kubernetes binds the Persistent Volumes to Claims based
on the request and properties set on the volume. Every Persistent Volume Claims is bound to single Persistent
volume during the binding process Kubernetes tries to find a persistent volume that has sufficient
capacity as requested by the claim and any other request properties such as access modes volume modes
storage class etc. However if there are multiple possible matches for a single claim and you would like
to specifically use a particular volume you could still use labels and selectors to bind to the right
volumes.
Finally note that a smaller claim may get bound to a larger volume if all the other criteria matches
and there are no better options.
There is a one to one relationship between claims and volumes so no other claims can utilize the remaining
capacity in the volume.
If there are no volumes available the persistent volume claim will remain in a pending state until newer
volumes are made available to the cluster once newer volumes are available.
The claim would automatically be bound to the newly available volume let us now create a persistent
volume claim.
We start with a blank template said the API version to V1 and kind to persistent volume claim.
We will name it myclaim. Under specification set the accessModes to ReadWriteOnce. And set resources
to request a storage of 500 mega bytes. Create the claim using kubectl create command. To view the
created claim run the kubectl get persistentvolumeclaim command. We see the claim in a pending state.
When the claim is created, kubernetes looks at the volume created previously. The access Modes match.
The capacity requested is 500 Megabytes but the volume is configured with 1 GB of storage. Since there
are no other volumes available.
The persistent volume claim is bound to persistent volume when we run to get volumes command again.
We see the claim is bound to the persistent volume we created perfect. To delete a PVC run the kubectl
delete persistent volume claim command but what happens to the underlying persistent volume when the
claim is deleted.
You can choose what is to happen to the volume by default.
It is set to retain meaning the persistent volume will remain until it is manually deleted by the administrator.
It is not available for reuse by any other claims or it can be deleted automatically.
This way as soon as the claim is deleted the volume will be deleted as well thus freeing up storage
on the end storage device or a third option is to recycle.
In this case the data in the data volume will be scrubbed before making it available to other claims
well that's it for this lecture.
Head over to the coding exercises section and practice configuring and troubleshooting persistent volumes
and volume claims in Kubernetes.