How to dynamically expand and shrink the PolarDB-X cluster

In order to facilitate user experience, PolarDB-X provides a free experimental environment, where you can experience the installation and deployment of PolarDB-X and various kernel features. In addition to free experiments, PolarDB-X also provides free video courses to teach you how to use the PolarDB-X distributed database.

This experiment will guide you to dynamically expand and contract PolarDB-X.

Free experimental address for this issue

Address of this teaching video

Preparation
Assuming that the PolarDB-X has been built and deployed according to the content of the previous lecture, the PolarDB-X database can be successfully linked.

expansion
1. Execute the following command to edit the polardb-x.yaml file.

vim polardb-x.yaml

2. Press the i key to enter the edit mode, change the replicas parameter of CN, DN and CDC to 2, and perform capacity expansion.


3. Press ECS to exit the edit mode, enter :wq and press Enter to save and exit.

4. Execute the following command to apply the modified polardb-x.yaml file to the created PolarDB-X cluster.

kubectl apply -f polardb-x.yaml

5. Execute the following command to observe the changes of the cluster.

kubectl get polardbxCluster polardb -x -o wide -w

The returned results are as follows, and you can see the changes of each node during the expansion of the PolarDB-X cluster. Please wait patiently for about two minutes. When the PHASE is displayed as Running, it means that the expansion of the PolarDB-X cluster has been completed.


6. Press Ctrl+C to exit and view the PolarDB-X cluster status.

7. Execute the following command to obtain the PolarDB-X cluster login password.

kubectl get secret polardb-x -o jsonpath="{.data['polardbx_root']}" | base64 -d - | xargs echo "Password: "
The returned results are as follows, and you can view the PolarDB-X cluster login password.


8. Execute the following command to forward the port of the PolarDB-X cluster to the local port 3306.

kubectl port-forward svc/polardb -x 3306

9. On the experiment page, click the + icon in the upper right corner to create a new terminal 2 window.


10. Execute the following command to connect to the PolarDB-X cluster.

Note: You need to replace with the obtained PolarDB-X cluster login password.

If you encounter ERROR 3933 (HY000): 1469bb175b401000[polardbx]ERR-CODE: PXC-9001 Failed to create physical db, dbName=[sysbench_test], instId=[polardb-x]. Error, please wait patiently for a minute , execute the SQL statement again.

mysql -h127.0.0.1 -P3306 -upolardbx_root -p

11. Execute the following SQL statement to check the status after capacity expansion.

show storage;
The returned results are as follows, and you can view the status of the expanded PolarDB-X cluster.

Shrinkage
Scale down the PolarDB-X cluster.

1. Switch to Terminal 1 and press Ctrl+C to stop PolarDB-X cluster port forwarding.

2. Execute the following command to edit the polardb-x.yaml file.

vim polardb-x.yaml

3. Press the i key to enter the editing mode, change the replicas parameter of CN, DN, and CDC to 1, and perform the scaling operation.

4. Press ECS to exit the edit mode, enter :wq and press Enter to save and exit.

5. Execute the following command to apply the modified polardb-x.yaml file to the created PolarDB-X cluster.

kubectl apply -f polardb-x.yaml

6. Execute the following command to observe the changes of the cluster.

kubectl get polardbxCluster polardb -x -o wide -w

The returned results are as follows, and you can see the changes of each node during the shrinking process of the PolarDB-X cluster. Please wait patiently for about two minutes. When PHASE is displayed as Running, it means that the PolarDB-X cluster has been scaled down.

7. Press Ctrl+C to exit and view the PolarDB-X cluster status.

8. Execute the following command to forward the port of the PolarDB-X cluster to the local port 3306.

kubectl port-forward svc/polardb -x 3306
9. Switch to terminal 2, execute the following SQL statement, and check the status after shrinking.

show storage;
The returned results are as follows, and you can view the status of the PolarDB-X cluster after shrinking.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us