Scenario
An application requires persistent storage that can be resized without downtime.
Task
Create a StorageClass, PVC, and Pod. Once the pod is running, expand the PVC to the expanded size without restarting the pod.
| Property |
Value |
| Namespace |
storage |
| StorageClass |
expandable-sc |
| PVC name |
data-pvc |
| Initial size |
1Gi |
| Expanded size |
5Gi |
| Pod name |
app-pod |
| Image |
nginx |
| Mount path |
/data |
Template files are available at /home/interview/.
Step 1: Edit StorageClass template sc.yaml to enable volume expansion
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: expandable-sc # Fix name
provisioner: rancher.io/local-path
allowVolumeExpansion: true # Fix: false -> true
volumeBindingMode: WaitForFirstConsumer
kubectl apply -f /home/interview/sc.yaml
Step 2: Edit PVC template pvc.yaml with correct values
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-pvc # Fix name
namespace: storage # Fix namespace
spec:
accessModes:
- ReadWriteOnce
storageClassName: expandable-sc # Fix storageClassName
resources:
requests:
storage: 1Gi # Fix size
kubectl apply -f /home/interview/pvc.yaml
Step 3: Edit pod template pod.yaml to mount the PVC
apiVersion: v1
kind: Pod
metadata:
name: app-pod # Fix name
namespace: storage # Fix namespace
spec:
containers:
- name: app
image: nginx
volumeMounts:
- name: data # Fix name
mountPath: /data # Fix path
volumes:
- name: data # Fix name
persistentVolumeClaim: # Fix: emptyDir -> persistentVolumeClaim
claimName: data-pvc # Add
kubectl apply -f /home/interview/pod.yaml
Step 4: Expand PVC to 5Gi (without restarting pod)
kubectl edit pvc data-pvc -n storage
Change spec.resources.requests.storage from 1Gi to 5Gi:
spec:
resources:
requests:
storage: 5Gi # Change from 1Gi to 5Gi
Step 5: Verify expansion
kubectl get pvc data-pvc -n storage