Migrate TiDB to Kubernetes
- The physical or virtual machines outside Kubernetes have network access to the Pods in Kubernetes.
- The physical or virtual machines outside Kubernetes can resolve the domain name of the Pods in Kubernetes. (See Step 1 for configuration details.)
- The cluster to be migrated (that is, the source cluster) does not .
Step 1: Configure DNS service in all nodes of the cluster to be migrated
Get the Pod IP address list of the endpoints of the CoreDNS or kube-dns service of the Kubernetes cluster:
Test whether the node can successfully resolve the domain name of the Pods in Kubernetes:
Get the PD node address and port of the source cluster via :
pd-ctl -u http://<address>:<port> member | jq '.members | .[] | .client_urls'
Create the target TiDB cluster in Kubernetes, which must have at least 3 TiKV nodes. Specify the PD node address of the source cluster in the
spec.pdAddresses
field (starting withhttp://
):Confirm that the source cluster and the target cluster compose of a new cluster that runs normally:
-
# Get the number of stores
# Get the state of stores
pd-ctl -u http://<address>:<port> store | jq '.stores | .[] | .store.state_name'
Access the TiDB cluster in Kubernetes via MySQL client.
-
Step 3: Scale in the TiDB nodes of the source cluster
Remove all TiDB nodes of the source cluster:
If the source cluster is deployed using TiUP, refer to Scale in a TiDB/PD/TiKV cluster.
If the source cluster is deployed using TiDB Ansible, refer to .
Note
If you access the source TiDB cluster via load balancer or database middleware, you need to first modify the configuration to route your application traffic to the target TiDB cluster. Otherwise, your application might be affected.
If the source cluster is deployed using TiUP, refer to Scale in a TiDB/PD/TiKV cluster.
If the source cluster is deployed using TiDB Ansible, refer to .
Note
- You need to scale in the TiKV nodes one by one. Wait until the store state of one TiKV node becomes “tombstone” and then scale in the next TiKV node.
- You can view the store state using PD Control.
Step 5: Scale in the PD nodes of the source cluster
Remove all PD nodes of the source cluster:
If the source cluster is deployed using TiUP, refer to .
If the source cluster is deployed using TiDB Ansible, refer to Decrease the capacity of a PD node.