Expanding a PVC
This guide is designed to assist you in managing your PVC utilization effectively. If you encounter an alert indicating that your PVC utilization has exceeded a specified limit, it may indicate that you need to resize your PVC.
When do you need to expand the PVC?
You might need to expand the PVC when you find the following error.
Example:
CRITICAL Alert: [Critical] Kubernetes Volume disk space < 15% available - [ 1.36956787109375 ](asi-uat-facets)
The following sections will provide a step-by-step walkthrough on how to examine and expand a PVC volume accordingly.
Prerequisites
Before you start, download the Kubeconfig file from the relevant Environment Overview page and set it as the active configuration in your terminal using the following command:
export KUBECONFIG=~/path-to-file/downloaded-kubeconfig
How to Check Disk Utilization?
- Download the script file from the link provided in this gist and save it as
kubedf.
- Run the
kubedf
command to display the usage of all disks. - If you are interested in a specific disk, filter the results using the
grep
command.
How to Resize PVCs in kubernetes?
- Open the terminal and execute the following command:
Ensure the Status of the PVC you plan to resize is either in a Bound or Available state.
kubectl get pvc <PVC_name>
- Determine the new size you want for the PVC.
- To resize the PVC, execute the following command:
where
kubectl patch pvc \<PVC_name> -p '{"spec":{"resources":{"requests":{"storage":"\<new_size>"}}}}'
<PVC_name>
is the name of the PVC and<new_size>
is the intended new size. - Confirm the resizing by running the following command:
The Capacity field should display the new size.
kubectl describe pvc <PVC_name>
- Ensure that the pod using this PVC is functioning correctly after the resize.
- For safety, make sure the pod utilizing this PVC runs in a stateful set or deployment with a single replica to avoid data loss.
- We recommend backing up the data in the PV before making any modifications.
- Check the compatibility of the new size with the storage class and the underlying storage system.
How to resize PVCs in Azure?
In Azure, there are two methods to resize PVCs that utilize Azure Managed Disks:
- Resizing with the LiveResize preview feature.
- Resizing with an associated period of downtime.
Resizing PVCs without downtime is possible if either the VM scale sets used for the nodes are supported or the LiveResize preview feature is enabled. If these options are not available, resizing the PVC will require a period of downtime.
How to Resize using the LiveResize preview feature?
Supported VM SKU's
Note: Ensure that the SKU name and Region are available (refer to the provided sheet for details) before proceeding. Without these, the utilization of the LiveResize preview feature for resizing is not possible. In such cases, you will need to proceed with Resizing with an associated period of downtime.
Enabling LiveResize preview
To enable the LiveResize feature, run the following commands:
- Verify if the LiveResize feature is already enabled by running:
az feature show --namespace Microsoft.Compute --name LiveResize
- Register the feature flag by running:
az feature register --namespace Microsoft.Compute --name LiveResize
After enabling the LiveResize feature, follow the steps in the How to Resize the PVC? section.
How to Resize with an associated period of downtime?
To Resize PVCs with an associated period of downtime, refer to the official Expand Azure disk PVC with downtime documentation.
References
Updated 7 months ago