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

    1. Get the Pod IP address list of the endpoints of the CoreDNS or kube-dns service of the Kubernetes cluster:

    2. Test whether the node can successfully resolve the domain name of the Pods in Kubernetes:

    1. Get the PD node address and port of the source cluster via :

      1. pd-ctl -u http://<address>:<port> member | jq '.members | .[] | .client_urls'
    2. 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 with http://):

    3. Confirm that the source cluster and the target cluster compose of a new cluster that runs normally:

        1. # Get the number of stores
        2. # Get the state of stores
        3. 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:

    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.

    Migrate TiDB to Kubernetes - 图2Note

    • 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: