How can I increase the storage size of a Persistent Volume Claim (PVC)?
To see a list of your PVCs, run the following command replacing
|
-
Confirm that the volume manager
storageClass
can support the increase on the cluster. For reference, you can use Kafka, Zookeeper, MongoDB, PostgreSQL, MinIO.-
Retrieve the
<storageclass_name>
of your PVC by running the following command line, replacing<namespace>
and<pvc_name>
with your values:kubectl -n <namespace> get pvc <pvc_name> -o jsonpath='{.spec.storageClassName}'
-
Check if your PVC can be increased by running the following command line, replacing
<storageclass_name>
with your value:kubectl get storageclasses.storage.k8s.io <storageclass_name> -o jsonpath='{.allowVolumeExpansion}'
If the response for
allowVolumeExpansion
istrue
, you can increase the storage of your PVC.
-
-
Scale down all pods using the PVC you want to edit by running the following command line, replacing
<namespace>
and, depending on your PVC, either<deployment_name>
or<statefulset_name>
with your values:kubectl -n <namespace> scale deployment/<deployment_name> --replicas 0 (1) kubectl -n <namespace> scale statefulset/<statefulset_name> --replicas 0 (1)
Where:
1 The 0
after--replicas
represents the action of scaling down a pod.Once you have confirmed that your
storageClass
supports the storage increase and you have scaled down your pod, you are ready to increase the storage size. -
Edit your PVC by running the following command line, replacing
<namespace>
and<pvc_name>
with your values:kubectl -n <namespace> edit pvc <pvc_name>
-
OPTIONAL: To get more information about your PVC, including the storage capacity, run the following command line replacing
<namespace>
and<pvc_name>
with your values:kubectl -n <namespace> describe pvc <pvc_name>
-
Locate the
spec
section of the response:spec: accessModes: - ReadWriteOnce dataSource: null resources: requests: storage: 32Gi storageClassName: common-storageclass volumeName: pvc-jhz434ui92
-
Change the
spec.resources.requests.storage
value with your new increased storage amount. Note that you can only increase storage. Decreasing storage is not supported.Once you have saved your changes, the output of the command should look like the following:
persistentvolumeclaim/<pvc_name> edited
Where:
-
<pvc_name>
is the name of your PVC.
-
-
Run the following command line, replacing
<namespace>
and<pvc_name>
with your values, to see the state of your PVC:kubectl -n <namespace> describe pvc <pvc_name>
The output of the command should look like the following:
Conditions: Type Status LastProbeTime LastTransitionTime Reason Message ---- ------ ----------------- ------------------ ------ ------- FileSystemResizePending True Mon, 01 Jan 0001 00:00:00 +0000 Fri, 13 Mar 2020 15:03:55 +0100 Waiting for user to (re-)start a pod to finish file system resize of volume on node.
-
Locate your
<replicas_default>
value by running adescribe
command for either adeployment
or astatefulset
, replacing<namespace>
and either<deployment_name>
or<statefulset_name>
with your values:kubectl -n <namespace> describe deployment <deployment_name> kubectl -n <namespace> describe statefulset <statefulset_name>
-
Run the same command used to scale down your pods, replacing the
0
with your<replicas_default>
value:Be sure to also replace <namespace>
and either<deployment_name>
or<statefulset_name>
with your values.kubectl -n <namespace> scale deployment/<deployment_name> --replicas <replicas_default> kubectl -n <namespace> scale statefulset/<statefulset_name> --replicas <replicas_default>
After scaling your pod, it will take a few minutes before the pod, with its new storage volume, is usable.