Deploy TiDB Operator and a TiDB Cluster on KubeSphere

    This tutorial demonstrates how to deploy TiDB Operator and a TiDB Cluster on KubeSphere.

    • You need to enable the OpenPitrix system.
    • You need to create a workspace, a project, and two user accounts ( and project-regular) for this tutorial. The account ws-admin must be granted the role of workspace-admin in the workspace, and the account project-regular must be invited to the project with the role of operator. If they are not ready, refer to .

    Hands-on Lab

    1. Log in to the KubeSphere Web console as admin, and use Kubectl from the Toolbox in the bottom right corner to execute the following command to install TiDB Operator CRD:

    2. You can see the expected output as below:

    Step 2: Add an app repository

    1. In the dialog that appears, enter pingcap for the app repository name and https://charts.pingcap.org for the PingCAP Helm repository URL. Click Validate to verify the URL and you will see a green check mark next to the URL if it is available. Click OK to continue.

    2. Your repository displays in the list after successfully imported to KubeSphere.

      added-pingcap-repo

    1. Log out of KubeSphere and log back in as project-regular. In your project, go to Applications under Application Workloads and click Deploy New Application.

    2. In the dialog that appears, select From App Templates.

      from-app-templates

    3. Select pingcap from the drop-down list, then click tidb-operator.

      Note

      This tutorial only demonstrates how to deploy TiDB Operator and a TiDB cluster. You can also deploy other tools based on your needs.

    4. On the Chart Files tab, you can view the configuration from the console directly or download the default values.yaml file by clicking the icon in the upper right corner. Under Versions, select a version number from the drop-down list and click Deploy.

      select-version

    5. On the Basic Info page, confirm the app name, app version, and deployment location. Click Next to continue.

    6. On the App Config page, you can either edit the values.yaml file, or click Deploy directly with the default configurations.

      check-config-file

    7. Go to Workloads, and you can see two Deployments created for TiDB Operator.

      tidb-deployment

    Step 4: Deploy a TiDB cluster

    The process of deploying a TiDB cluster is similar to deploying TiDB Operator.

    1. Go to Applications under Application Workloads, click Deploy New Application again, and then select From App Templates.

      from-app-templates-2

    2. From the PingCAP repository, click tidb-cluster.

    3. On the Basic Info page, confirm the app name, app version, and deployment location. Click Next to continue.

      tidb-cluster-info

    4. Some TiDB components require . You can run the following command to view your storage classes.

    5. On the App Config page, change the default value of the field storageClassName from local-storage to the name of your storage class. For example, you can change it to csi-qingcloud based on the above output.

      Note

      Only the field storageClassName is changed to provide external persistent storage. If you want to deploy each TiDB component, such as TiKV and , to individual nodes, specify the field nodeAffinity.

    6. Click Deploy and you can see two apps in the list as shown below:

      tidb-cluster-app-running

    1. Go to Workloads under Application Workloads, and verify that all TiDB cluster Deployments are up and running.

    2. Switch to the StatefulSets tab, and you can see TiDB, TiKV and PD are up and running.

      Note

      TiKV and TiDB will be created automatically and it may take a while before they display in the list.

    3. Click a single StatefulSet to go to its detail page. You can see the metrics in line charts over a period of time under the Monitoring tab.

      TiDB metrics:

      tidb-metrics

      TiKV metrics:

      PD metrics:

      pd-metrics

    4. In Pods under Application Workloads, you can see the TiDB cluster contains two TiDB Pods, three TiKV Pods, and three PD Pods.

    5. In Volumes under Storage, you can see TiKV and PD are using persistent volumes.

      tidb-storage-usage

    6. Volume usage is also monitored. Click a volume item to go to its detail page. Here is an example of TiKV:

    7. On the Overview page of the project, you can see a list of resource usage in the current project.

      tidb-project-resource-usage

    Step 6: Access the TiDB cluster

    1. Go to Services under Application Workloads, and you can see detailed information of all Services. As the Service type is set to NodePort by default, you can access it through the Node IP address outside the cluster.