📖 Scenario: You are managing a Kubernetes cluster that needs to automatically create storage volumes for applications when they request storage. This is called dynamic provisioning. You will create a StorageClass to define how storage is dynamically created, then create a PersistentVolumeClaim that uses this StorageClass.
🎯 Goal: Build a StorageClass named fast-storage that provisions storage dynamically with the kubernetes.io/aws-ebs provisioner and a PersistentVolumeClaim named fast-pvc that uses this StorageClass to request 5Gi of storage.
📋 What You'll Learn
Create a StorageClass named fast-storage with provisioner kubernetes.io/aws-ebs
Set the StorageClass parameter type to gp2
Create a PersistentVolumeClaim named fast-pvc that uses the fast-storage StorageClass
Request exactly 5Gi of storage in the PersistentVolumeClaim
Use access mode ReadWriteOnce in the PersistentVolumeClaim
💡 Why This Matters
🌍 Real World
Dynamic provisioning allows Kubernetes to automatically create storage volumes when applications need them, saving manual setup time and reducing errors.
💼 Career
Understanding StorageClasses and PVCs is essential for Kubernetes administrators and DevOps engineers managing stateful applications in cloud environments.
Progress0 / 4 steps
1
Create the StorageClass manifest
Create a YAML manifest for a StorageClass named fast-storage with the provisioner set to kubernetes.io/aws-ebs.
Kubernetes
Hint
The kind must be StorageClass. The metadata.name is fast-storage. The provisioner is kubernetes.io/aws-ebs. Add parameters: with type: gp2.
2
Create the PersistentVolumeClaim manifest
Create a YAML manifest for a PersistentVolumeClaim named fast-pvc that uses the StorageClass fast-storage.
Kubernetes
Hint
The kind is PersistentVolumeClaim. The metadata.name is fast-pvc. Under spec, set storageClassName to fast-storage. Request 5Gi storage and use access mode ReadWriteOnce.
3
Apply the manifests to the cluster
Use the kubectl apply -f command to apply the YAML file containing both the StorageClass and PersistentVolumeClaim manifests.
Kubernetes
Hint
Use kubectl apply -f storage.yaml to create the StorageClass and PersistentVolumeClaim in the cluster.
4
Verify the PersistentVolumeClaim status
Run the command kubectl get pvc fast-pvc to check the status of the PersistentVolumeClaim and print the output.
Kubernetes
Hint
Run kubectl get pvc fast-pvc to see the status. The output should include the name fast-pvc and show its status like Bound.
Practice
(1/5)
1. What is the main purpose of a StorageClass in Kubernetes?
easy
A. To define how storage volumes are dynamically provisioned
B. To schedule pods on specific nodes
C. To manage network policies
D. To configure container resource limits
Solution
Step 1: Understand StorageClass role
A StorageClass defines parameters for dynamic volume provisioning in Kubernetes.
Step 2: Compare with other options
Scheduling pods, managing network policies, and resource limits are unrelated to StorageClass.
Final Answer:
To define how storage volumes are dynamically provisioned -> Option A
Quick Check:
StorageClass = dynamic provisioning [OK]
Hint: StorageClass controls storage creation, not pods or network [OK]
What will happen when a PersistentVolumeClaim requests storage from this class?
medium
A. The volume will not be dynamically provisioned; manual provisioning is required
B. The volume will be deleted automatically when released
C. The volume will be dynamically provisioned immediately
D. The volume will be provisioned but bound immediately without waiting
Solution
Step 1: Analyze provisioner field
The provisioner is kubernetes.io/no-provisioner, meaning no dynamic provisioning.
Step 2: Understand reclaimPolicy and binding mode
ReclaimPolicy is Retain (volume kept after release), and volumeBindingMode waits for pod scheduling.
Final Answer:
The volume will not be dynamically provisioned; manual provisioning is required -> Option A
Quick Check:
No provisioner = manual provisioning [OK]
Hint: No provisioner means no dynamic provisioning [OK]
Common Mistakes:
Assuming dynamic provisioning happens with no-provisioner
Confusing reclaimPolicy with provisioning behavior
Ignoring volumeBindingMode effect
4. You created a StorageClass with volumeBindingMode: Immediate but your pods fail to schedule because volumes are not available in the node's zone. What is the likely cause and fix?
medium
A. Cause: StorageClass name mismatch; Fix: Correct PVC storageClassName
B. Cause: Reclaim policy is Retain; Fix: Change to Delete
C. Cause: Provisioner is missing; Fix: Add a provisioner
D. Cause: Immediate binding ignores pod location; Fix: Change to WaitForFirstConsumer
Solution
Step 1: Understand volumeBindingMode impact
Immediate binding provisions and binds volume before pod scheduling, ignoring node zone.
Step 2: Identify fix
Changing to WaitForFirstConsumer delays binding until pod scheduling, ensuring volume is in correct zone.
Final Answer:
Cause: Immediate binding ignores pod location; Fix: Change to WaitForFirstConsumer -> Option D
Quick Check:
Immediate binding ignores pod zone [OK]
Hint: Use WaitForFirstConsumer to bind volume after pod scheduling [OK]
Common Mistakes:
Changing reclaimPolicy instead of binding mode
Adding provisioner when already present
Fixing storageClassName without checking binding mode
5. You want to create a StorageClass that dynamically provisions SSD-backed volumes with fast performance, deletes volumes when released, and delays binding until pod scheduling. Which YAML snippet correctly implements this?
hard
A. apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-ssd
provisioner: kubernetes.io/aws-ebs
parameters:
type: standard
reclaimPolicy: Retain
volumeBindingMode: Immediate