Online Volume Expansion
You raise the storage request of a PVC from 5Gi to 20Gi, yet for a while df in its Pod still reports 5Gi. What has to happen before the extra room shows up, and why is shrinking it back afterwards refused outright?
Play the animation 6 steps, animated, plays on a computer or a tablet
Online Volume Expansion, step by step
-
You raise spec.resources.requests.storage on the claim from 5Gi to 20Gi, the only change anybody makes by hand. The request now says 20Gi, but nothing physical has changed, since the device and the filesystem are both still 5Gi.
Play from step 1 -
That edit was accepted only because of one field on the StorageClass the claim names: allowVolumeExpansion is true. The check runs at admission, on the API server, so with the flag false or absent the edit itself is rejected and no resizer ever hears about it.
Play from step 2 -
Phase one runs on the controller side. The external-resizer sees the accepted request and calls ControllerExpandVolume on the driver, and the driver tells the backend to grow the real block device from 5Gi to 20Gi. The device is now bigger and the PV capacity follows it. The filesystem on it knows nothing of this and is still 5Gi.
Play from step 3 -
Phase two runs on the Node. Kubelet calls NodeExpandVolume, which grows the filesystem on the mounted device to fill the larger disk. This half runs only on a Node where a Pod uses the claim read-write, so with no such Pod it waits for one to start. A raw block volume has no filesystem to grow, so a driver may skip that work.
Play from step 4 -
Only now does the space reach the workload. The device grew, then the filesystem grew, and because this filesystem grows online the extra room shows up inside the running container with no restart, so df in web-0 finally reads 20Gi. The order matters because a filesystem can never grow past the device underneath it.
Play from step 5 -
Growing works, going back does not. A request for less than the volume already has is refused by the API, because there is no safe general way to shrink a filesystem with live data on it. Walking a request back down after an expansion failed is a different thing. It retries a smaller grow, still above the current size.
Play from step 6