CKA — Volume Expansion

4 minute read

CKA Exam Domain

Storage — 10%

Volume expansion lets you increase the size of a PVC without recreating it. This is a practical skill for the CKA exam — you may need to resize a volume as part of a troubleshooting or configuration task.

AllowVolumeExpansion

For a PVC to be expandable, the StorageClass must have allowVolumeExpansion: true:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: expandable
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
reclaimPolicy: Delete

If the StorageClass does not have this field set to true, any attempt to expand the PVC will be rejected.

Check if a StorageClass allows expansion:

kubectl get storageclass expandable -o jsonpath='{.allowVolumeExpansion}'

Exam tip: If you are asked to expand a PVC and it fails, the first thing to check is whether the StorageClass has allowVolumeExpansion: true.

Expanding a PVC

There are two main ways to expand a PVC:

Using kubectl edit

kubectl edit pvc pvc-demo

In the editor, change the spec.resources.requests.storage value:

spec:
  resources:
    requests:
      storage: 5Gi   # was 3Gi, now 5Gi

Save and exit.

Using kubectl patch

kubectl patch pvc pvc-demo -p '{"spec":{"resources":{"requests":{"storage":"5Gi"}}}}'

Both methods achieve the same result. On the exam, kubectl patch is faster if you know the exact syntax.

Exam tip: kubectl edit opens a full YAML editor — useful when you need to see and modify multiple fields. kubectl patch is a one-liner — faster for single-field changes.

Online vs Offline Expansion

Volume expansion can happen in two ways depending on the storage driver:

Type Description Pod Action Required
Online expansion Volume is resized while the Pod is running and the volume is mounted None — seamless
Offline expansion Volume resize requires the Pod to be deleted and recreated Delete Pod, wait for resize, recreate Pod

How to Tell Which You Need

  • Most CSI drivers support online expansion (AWS EBS, GCE PD, Azure Disk)
  • Some older drivers require offline expansion
  • The PVC conditions will tell you if a restart is needed

Check PVC conditions:

kubectl get pvc pvc-demo -o yaml | grep -A 5 conditions

If you see FileSystemResizePending, the PV has been resized but the filesystem has not. Deleting and recreating the Pod will trigger filesystem expansion.

File System Expansion

Volume expansion is a two-step process:

  1. PV resize — The underlying storage is expanded (handled by the provisioner)
  2. Filesystem resize — The filesystem inside the volume is expanded to use the new space

The filesystem resize typically happens automatically when:

  • The Pod is running and the volume is mounted (online expansion)
  • A new Pod mounts the volume after PV resize (offline expansion)

You do not need to manually run filesystem resize commands — Kubernetes handles it.

Limitations and Gotchas

Keep these in mind for the exam:

  • Can only INCREASE, never decrease — You cannot shrink a PVC. If you try to reduce the storage size, the request will be rejected.
  • StorageClass must allow it — allowVolumeExpansion: true must be set on the StorageClass.
  • Some CSI drivers need offline expansion — Check if the Pod needs to be deleted and recreated after the resize.
  • Watch PVC conditions for resize status — The status.conditions field will tell you the current state of the expansion.
  • Expansion may take time — Depending on the storage backend, the resize operation may not be instant.
  • StatefulSet volumes — PVCs owned by StatefulSets can be expanded, but you need to update each PVC individually.

Common Error

If you try to expand a PVC without allowVolumeExpansion:

error: persistentvolumeclaims "pvc-demo" could not be patched: 
persistentvolumeclaims "pvc-demo" is forbidden: only dynamically provisioned pvc 
can be resized and the storageclass that provisions the pvc must support resize

Verifying Expansion

After expanding a PVC, verify the new size:

# Check PVC status
kubectl get pvc pvc-demo

Expected output:

NAME       STATUS   VOLUME    CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-demo   Bound    pv-demo   5Gi        RWO            expandable     10m

Get detailed capacity information:

# Check capacity from the PVC
kubectl describe pvc pvc-demo | grep -i capacity

# Check capacity from the PV
kubectl get pv -o custom-columns=NAME:.metadata.name,CAPACITY:.spec.capacity.storage

Verify from inside the Pod:

kubectl exec -it <pod-name> -- df -h /data

This shows the actual filesystem size, confirming the expansion was successful.

Practice Questions

Q1. A StorageClass does not have allowVolumeExpansion set. Can you expand PVCs using this StorageClass?

Show Answer

No. The allowVolumeExpansion field defaults to false when not specified. You must set it to true on the StorageClass before PVCs can be expanded.

To fix it:

kubectl patch storageclass <sc-name> -p '{"allowVolumeExpansion": true}'

Q2. Expand the PVC data-pvc from 1Gi to 5Gi using a single command.

Show Answer
kubectl patch pvc data-pvc -p '{"spec":{"resources":{"requests":{"storage":"5Gi"}}}}'

Then verify:

kubectl get pvc data-pvc

Q3. After expanding a PVC, the PVC shows the new size but df -h inside the Pod still shows the old size. What is happening?

Show Answer

The PV has been resized, but the filesystem has not been expanded yet. This is the FileSystemResizePending state.

To trigger filesystem expansion:

  1. Delete the Pod using the PVC
  2. Wait for the PVC condition to clear
  3. Recreate the Pod (or let a controller like a Deployment recreate it)

When the new Pod mounts the volume, the filesystem will be expanded automatically.

Q4. Can you decrease the size of a PVC from 10Gi to 5Gi?

Show Answer

No. Kubernetes only supports increasing PVC size — you cannot shrink a PVC. If you need a smaller volume, you must:

  1. Create a new smaller PVC
  2. Copy data from the old volume to the new one
  3. Update the Pod to use the new PVC
  4. Delete the old PVC

Q5. How do you check if a volume expansion is still in progress?

Show Answer

Check the PVC conditions:

kubectl describe pvc <pvc-name> | grep -A 10 Conditions

Or in YAML:

kubectl get pvc <pvc-name> -o yaml | grep -A 5 conditions

Look for these condition types:

  • Resizing — expansion is in progress
  • FileSystemResizePending — PV resized, waiting for filesystem expansion

Once the expansion is complete, the conditions will be cleared.

Updated: