Scenario
The cluster has no StorageClass configured for dynamic volume expansion.
Task
Create a StorageClass with volume expansion enabled, create a PVC and Pod using it, then expand the PVC from 1Gi to 2Gi.
| Property |
Value |
| Namespace |
storage |
| StorageClass name |
fast-sc |
| PVC name |
expand-pvc |
| Initial PVC size |
1Gi |
| Expanded PVC size |
2Gi |
| Pod name |
storage-pod |
| Pod image |
nginx |
| Mount path |
/data |
Resource templates are available at /home/interview/.
Step 1: Edit StorageClass template storageclass.yaml:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-sc # Fix: my-storage -> fast-sc
provisioner: rancher.io/local-path
allowVolumeExpansion: true # Fix: false -> true
volumeBindingMode: WaitForFirstConsumer
kubectl apply -f /home/interview/storageclass.yaml
Step 2: Edit PVC template pvc.yaml:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: expand-pvc # Fix: my-pvc -> expand-pvc
namespace: storage # Fix: default -> storage
spec:
accessModes:
- ReadWriteOnce
storageClassName: fast-sc # Fix: standard -> fast-sc
resources:
requests:
storage: 1Gi # Fix: 500Mi -> 1Gi
kubectl apply -f /home/interview/pvc.yaml
Step 3: Generate Pod manifest and add PVC mount:
kubectl run storage-pod --image=nginx -n storage --dry-run=client -o yaml > /home/interview/pod.yaml
Edit pod.yaml to add volume mount:
apiVersion: v1
kind: Pod
metadata:
name: storage-pod
namespace: storage
spec:
containers:
- name: storage-pod
image: nginx
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: expand-pvc
kubectl apply -f /home/interview/pod.yaml
kubectl wait --for=condition=Ready pod/storage-pod -n storage --timeout=60s
Step 4: Expand PVC to 2Gi:
kubectl edit pvc expand-pvc -n storage
Change spec.resources.requests.storage from 1Gi to 2Gi.
Step 5: Verify:
kubectl get storageclass fast-sc
kubectl get pvc expand-pvc -n storage
kubectl get pod storage-pod -n storage