High availability is essential for distributed applications. In an ACK serverless cluster, you can use native Kubernetes scheduling semantics to spread distributed applications across multiple zones to achieve a high-availability deployment. This document describes how to deploy a stateful, high-availability MySQL cluster on ACK Serverless.
Prerequisites
An ACK serverless cluster that contains multiple virtual nodes has been created. For more information, see Create an ACK Serverless cluster.
Virtual node scheduling policies have been enabled. For more information, see Enable virtual node scheduling policies for a cluster.
The csi-provisioner component of version v1.22.9 or later is installed.
Step 1: Pull YAML files from GitHub to create Kubernetes resources
Run the following command to clone the code repository.
git clone https://github.com/AliyunContainerService/serverless-k8s-examples.gitRun the following command to navigate to the working directory and view the list of YAML files.
cd serverless-k8s-examples/stateful-mysql ls -alExpected output:
README.md secret.yaml stateful-mysql.yaml storageclass.yamlThe
secret.yamlfile is used to create a Secret, thestorageclass.yamlfile is used to create a StorageClass, and thestateful-mysql.yamlfile is used to create a MySQL StatefulSet.
Step 2: Create a namespace, Secret, and StorageClass
Run the following command to create the
mysqlnamespace.kubectl create namespace mysqlExpected output:
namespace/mysql createdRun the following command to create a Secret to store the MySQL password.
kubectl apply -n mysql -f secret.yamlExpected output:
secret/mysql-secret createdThe following is the YAML file for the Secret.
Run the following command to create a StorageClass.
kubectl apply -f storageclass.yamlExpected output:
storageclass.storage.k8s.io/fast-storageclass createdThe following is the YAML file for the StorageClass.
Step 3: Configure pod topology spread and create a MySQL StatefulSet
Run the following command to create a MySQL StatefulSet. This example creates a StatefulSet that is evenly distributed across multiple zones by configuring pod topology spread constraints for virtual nodes. For more information about how to spread pods across zones on virtual nodes, see Spread pods on virtual nodes across zones and configure affinity.
kubectl apply -n mysql -f stateful-mysql.yamlExpected output:
statefulset.apps/dbc1 createdThe following is the YAML file for the StatefulSet.
Step 4: Verify the deployment of pods in the MySQL cluster
Run the following command to verify that the StatefulSet is created.
kubectl get statefulset -n mysqlExpected output:
NAME READY AGE dbc1 3/3 7m21sRun the following command to view the details of the pods.
kubectl -n mysql get po -o wideExpected output:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES dbc1-0 1/1 Running 0 2m28s 10.1.214.213 virtual-kubelet-cn-hangzhou-j <none> <none> dbc1-1 1/1 Running 0 106s 10.3.146.113 virtual-kubelet-cn-hangzhou-h <none> <none> dbc1-2 1/1 Running 0 64s 10.4.232.78 virtual-kubelet-cn-hangzhou-g <none> <none>The `NODE` column shows the node where each pod is deployed. The node name contains the zone information. The node names indicate that the pods are spread across different zones.