Deploy TiDB in General Kubernetes

This document describes how to deploy a TiDB cluster in general Kubernetes.

Prerequisites

Deploy the TiDB cluster

  1. Create Namespace:

    1. kubectl create namespace ${namespace}

    Deploy a TiDB Cluster - 图1Note

    A namespace is a virtual cluster backed by the same physical cluster. You can give it a name that is easy to memorize, such as the same name as cluster_name.

  2. Deploy the TiDB cluster:

    1. kubectl apply -f ${cluster_name} -n ${namespace}

    Deploy a TiDB Cluster - 图2Note

    It is recommended to organize configurations for a TiDB cluster under a directory of cluster_name and save it as ${cluster_name}/tidb-cluster.yaml.

    If the server does not have an external network, you need to download the Docker image used by the TiDB cluster on a machine with Internet access and upload it to the server, and then use docker load to install the Docker image on the server.

    To deploy a TiDB cluster, you need the following Docker images (assuming the version of the TiDB cluster is v5.4.0):

    1. pingcap/pd:v5.4.0
    2. pingcap/tikv:v5.4.0
    3. pingcap/tidb:v5.4.0
    4. pingcap/tidb-binlog:v5.4.0
    5. pingcap/ticdc:v5.4.0
    6. pingcap/tiflash:v5.4.0
    7. pingcap/tidb-monitor-reloader:v1.0.1
    8. pingcap/tidb-monitor-initializer:v5.4.0
    9. grafana/grafana:6.0.1
    10. prom/prometheus:v2.18.1
    11. busybox:1.26.2

    Next, download all these images with the following command:

    1. docker pull pingcap/pd:v5.4.0
    2. docker pull pingcap/tikv:v5.4.0
    3. docker pull pingcap/tidb:v5.4.0
    4. docker pull pingcap/tidb-binlog:v5.4.0
    5. docker pull pingcap/ticdc:v5.4.0
    6. docker pull pingcap/tiflash:v5.4.0
    7. docker pull pingcap/tidb-monitor-reloader:v1.0.1
    8. docker pull pingcap/tidb-monitor-initializer:v5.4.0
    9. docker pull grafana/grafana:6.0.1
    10. docker pull prom/prometheus:v2.18.1
    11. docker pull busybox:1.26.2
    12. docker save -o pd-v5.4.0.tar pingcap/pd:v5.4.0
    13. docker save -o tikv-v5.4.0.tar pingcap/tikv:v5.4.0
    14. docker save -o tidb-v5.4.0.tar pingcap/tidb:v5.4.0
    15. docker save -o tidb-binlog-v5.4.0.tar pingcap/tidb-binlog:v5.4.0
    16. docker save -o ticdc-v5.4.0.tar pingcap/ticdc:v5.4.0
    17. docker save -o tiflash-v5.4.0.tar pingcap/tiflash:v5.4.0
    18. docker save -o tidb-monitor-reloader-v1.0.1.tar pingcap/tidb-monitor-reloader:v1.0.1
    19. docker save -o tidb-monitor-initializer-v5.4.0.tar pingcap/tidb-monitor-initializer:v5.4.0
    20. docker save -o grafana-6.0.1.tar grafana/grafana:6.0.1
    21. docker save -o prometheus-v2.18.1.tar prom/prometheus:v2.18.1
    22. docker save -o busybox-1.26.2.tar busybox:1.26.2

    Next, upload these Docker images to the server, and execute docker load to install these Docker images on the server:

    1. docker load -i pd-v5.4.0.tar
    2. docker load -i tikv-v5.4.0.tar
    3. docker load -i tidb-v5.4.0.tar
    4. docker load -i tidb-binlog-v5.4.0.tar
    5. docker load -i ticdc-v5.4.0.tar
    6. docker load -i tiflash-v5.4.0.tar
    7. docker load -i tidb-monitor-reloader-v1.0.1.tar
    8. docker load -i tidb-monitor-initializer-v5.4.0.tar
    9. docker load -i grafana-6.0.1.tar
    10. docker load -i prometheus-v2.18.1.tar
    11. docker load -i busybox-1.26.2.tar
  3. View the Pod status:

    1. kubectl get po -n ${namespace} -l app.kubernetes.io/instance=${cluster_name}

You can use TiDB Operator to deploy and manage multiple TiDB clusters in a single Kubernetes cluster by repeating the above procedure and replacing cluster_name with a different name.

Different clusters can be in the same or different namespace, which is based on your actual needs.

Deploy a TiDB Cluster - 图3Note

If you need to deploy a TiDB cluster on ARM64 machines, refer to Deploy a TiDB Cluster on ARM64 Machines.

Initialize the TiDB cluster

If you want to initialize your cluster after deployment, refer to Initialize a TiDB Cluster in Kubernetes.

Deploy a TiDB Cluster - 图4Note

By default, TiDB (starting from v4.0.2) periodically shares usage details with PingCAP to help understand how to improve the product. For details about what is shared and how to disable the sharing, see Telemetry.