Expand volume
You can expand the storage volume size of each pod.
Before you start
Check whether the cluster status is Running
. Otherwise, the following operations may fail.
- kbcli
- kubectl
kbcli cluster list mycluster
>
NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME
mycluster demo mysql mysql-8.0.33 Delete Running Jul 05,2024 18:46 UTC+0800
kubectl get cluster mycluster -n demo
>
NAME CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS AGE
mycluster mysql mysql-8.0.33 Delete Running 4d18h
Steps
- kbcli
- OpsRequest
- Edit cluster YAML file
Configure the values of
--components
,--volume-claim-templates
, and--storage
, and run the command below to expand the volume.kbcli cluster volume-expand mycluster -n demo --components="mysql" --volume-claim-templates="data" --storage="40Gi"
--components
describes the component name for volume expansion.--volume-claim-templates
describes the VolumeClaimTemplate names in components.--storage
describes the volume storage size.
Validate the volume expansion operation. There are two options.
View the OpsRequest progress.
KubeBlocks outputs a command automatically for you to view the details of the OpsRequest progress. The output includes the status of this OpsRequest and PVC. When the status is
Succeed
, this OpsRequest is completed.kbcli cluster describe-ops mycluster-volumeexpansion-8257f -n demo
View the cluster status.
kbcli cluster list mycluster -n demo
>
NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME
mycluster demo mysql mysql-8.0.33 Delete Running Jul 05,2024 18:46 UTC+0800- STATUS=Updating: it means the volume expansion is in progress.
- STATUS=Running: it means the volume expansion operation has been applied.
After the OpsRequest status is
Succeed
or the cluster status isRunning
again, check whether the corresponding resources change.kbcli cluster describe mycluster -n demo
Apply an OpsRequest. Change the value of storage according to your need and run the command below to expand the volume of a cluster.
kubectl apply -f - <<EOF
apiVersion: apps.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: ops-volume-expansion
namespace: demo
spec:
clusterName: mycluster
type: VolumeExpansion
volumeExpansion:
- componentName: mysql
volumeClaimTemplates:
- name: data
storage: "40Gi"
EOFValidate the volume expansion operation.
kubectl get ops -n demo
>
NAMESPACE NAME TYPE CLUSTER STATUS PROGRESS AGE
demo ops-volume-expansion VolumeExpansion mycluster Succeed 3/3 6mCheck whether the corresponding cluster resources change.
kubectl describe cluster mycluster -n demo
>
......
Volume Claim Templates:
Name: data
Spec:
Access Modes:
ReadWriteOnce
Resources:
Requests:
Storage: 40Gi
Change the value of
spec.componentSpecs.volumeClaimTemplates.spec.resources
in the cluster YAML file.spec.componentSpecs.volumeClaimTemplates.spec.resources
is the storage resource information of the pod and changing this value triggers the volume expansion of a cluster.apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mycluster
namespace: demo
spec:
clusterDefinitionRef: mysql
clusterVersionRef: mysql-8.0.33
componentSpecs:
- name: mysql
componentDefRef: mysql
replicas: 2
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 40Gi # Change the volume storage size.
terminationPolicy: DeleteCheck whether the corresponding cluster resources change.
kubectl describe cluster mycluster -n demo
>
......
Volume Claim Templates:
Name: data
Spec:
Access Modes:
ReadWriteOnce
Resources:
Requests:
Storage: 40Gi