Persistent Volumes and Persistent Volume Claims

are two separate objects in the Kubernetes name space.

An administrator creates a set of persistent volumes, and a user creates persistent volume claims to use the 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 Claim is bound to a single Persistent Volume.

There is a one to one relationship between claims and volumes, so no other claims can utilize the remaining capacity in the volume.

Link to original

Multiple PV for one PVC

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, et cetera. 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.

Important

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.

Config File

We see the claim in a pending state.

When the claim is created,

PVC Binding

Kubernetes looks at the volume created previously. The access modes match.

The capacity requested is 500 megabytes, but the volume is configured with one GB of storage.

Since there are no other volumes available, the Persistent Volume Claim is bound to the Persistent Volume.

When we run the get volumes command, again,

we see the claim is bound

to the Persistent Volume we created.

Perfect.

Delete PVC

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.