This article explores Kubernetes storage classes, their behavior, and hands-on labs for creating persistent volume claims and deploying pods for volume binding.
Use this file to discover all available pages before exploring further.
In this lesson, we will explore storage classes in Kubernetes by reviewing their behavior and running hands-on labs. You will learn how to list storage classes, examine their properties, create persistent volume claims (PVCs), and deploy a pod to trigger volume binding. Finally, we will create a new storage class with on-demand binding.
Step 3: Working with Persistent Volumes (PVs) and Persistent Volume Claims (PVCs)
First, check if there is any PVC consuming a persistent volume (PV) named local-pv:
kubectl get pv
Example output:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGElocal-pv 500Mi RWO Retain Available local-storage local-storage - 110s
Next, verify that there are no PVCs created yet:
kubectl get pvc
Expected output:
No resources found in default namespace.
Since no PVC exists, create one that binds to the PV. The PVC must request 500Mi of storage, use the ReadWriteOnce access mode, and specify the local-storage storage class. Create a file named pvc.yaml with the following content:
After applying the YAML file, check the PVC status:
kubectl get pvc
Initially, the PVC may display a Pending status:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGElocal-pvc Pending <none> <none> <none> local-storage 4s
For further details, inspect the PVC using:
kubectl describe pvc local-pvc
You might see an event similar to:
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal WaitForFirstConsumer 6s (x4 over 49s) persistentvolume-controller waiting for first consumer to be created before binding
This indicates that the WaitForFirstConsumer volume binding mode delays binding until a pod consumes the PVC.
Deploy a pod named nginx that uses the PVC to initiate binding. This pod will run the nginx:alpine image and mount the PVC at /var/www/html. Refer to the image below for guidance:
Create a file named nginx.yaml with the following configuration:
Step 5: Creating a New Storage Class with Delayed Binding
Finally, create a new storage class called delayed-volume-sc. This storage class utilizes a no-provisioner and employs the WaitForFirstConsumer volume binding mode. Prepare a file named delayed-volume-sc.yaml with the following content:
Listing and determining the number of storage classes in a Kubernetes cluster.
Understanding the difference between dynamic and non-dynamic volume provisioning.
Creating a PersistentVolumeClaim (PVC) and observing its binding behavior under the WaitForFirstConsumer mode.
Deploying a consumer pod (nginx) that triggers PVC binding.
Creating a new storage class with delayed (on-demand) volume binding.
With these steps, you are now familiar with storage class configurations and the process of volume binding in Kubernetes. Enjoy managing your storage solutions efficiently!For more details on Kubernetes storage, see Kubernetes Documentation.