Sign In Try Free

Tools on Kubernetes

Operations on TiDB on Kubernetes require some open source tools. In the meantime, there are some special requirements for operations using TiDB tools in the Kubernetes environment. This documents introduces in details the related operation tools for TiDB on Kubernetes.

Use PD Control on Kubernetes

PD Control是the command-line tool for PD (Placement Driver). To use PD Control to operate on TiDB clusters on Kubernetes, firstly you need to establish the connection from local to the PD service usingkubectl port-forward:


              
kubectl port-forward -n${namespace}svc/${cluster_name}-pd 2379:2379 &>/tmp/portforward-pd.log &

After the above command is executed, you can access the PD service via127.0.0.1:2379, and then use the default parameters ofpd-ctlto operate. For example:


              
pd-ctl -d config show

Assume that your local port2379has been occupied and you want to switch to another port:


              
kubectl port-forward -n${namespace}svc/${cluster_name}-pd${local_port}: 2379 & > / tmp / portforward-pd.log &

Then you need to explicitly assign a PD port forpd-ctl:


              
pd-ctl -u 127.0.0.1:${local_port}-d config show

Use TiKV Control on Kubernetes

TiKV Control是the command-line tool for TiKV. When using TiKV Control for TiDB clusters on Kubernetes, be aware that each operation mode involves different steps, as described below:

  • Remote Mode: In this mode,tikv-ctlaccesses the TiKV service or the PD service through network. Firstly you need to establish the connection from local to the PD service and the target TiKV node usingkubectl port-forward:

    
                    
    kubectl port-forward -n${namespace}svc/${cluster_name}-pd 2379:2379 &>/tmp/portforward-pd.log &
    
                    
    kubectl port-forward -n${namespace} ${pod_name}20160:20160 &>/tmp/portforward-tikv.log &

    After the connection is established, you can access the PD service and the TiKV node via the corresponding port in local:

    
                    
    tikv-ctl --host 127.0.0.1:20160${subcommands}
    
                    
    tikv-ctl --pd 127.0.0.1:2379 compact-cluster
  • Local Mode:In this mode,tikv-ctlaccesses data files of TiKV, and the running TiKV instances must be stopped. To operate in the local mode, first you need to enter theDebug Modeto turn off automatic re-starting for the TiKV instance, stop the TiKV process, and enter the target TiKV Pod and usetikv-ctlto perform the operation. The steps are as follows:

    1. Enter the debug mode:

      
                        
      kubectl annotate pod${pod_name}-n${namespace}runmode=debug
    2. Stop the TiKV process:

      
                        
      kubectlexec ${pod_name}-n${namespace}-c tikv --kill-s TERM 1
    3. Wait for the TiKV container to restart, and enter the container:

      
                        
      kubectlexec-it${pod_name}-n${namespace}-- sh
    4. Start usingtikv-ctlin local mode. The default db path in the TiKV container is/var/lib/tikv/db:

      
                        
      ./tikv-ctl --data-dir /var/lib/tikv size -r 2

Use TiDB Control on Kubernetes

TiDB Control是the command-line tool for TiDB. To use TiDB Control on Kubernetes, you need to access the TiDB node and the PD service from local. It is suggested you turn on the connection from local to the TiDB node and the PD service usingkubectl port-forward:


              
kubectl port-forward -n${namespace}svc/${cluster_name}-pd 2379:2379 &>/tmp/portforward-pd.log &

              
kubectl port-forward -n${namespace} ${pod_name}10080:10080 &>/tmp/portforward-tidb.log &

Then you can use thetidb-ctl:


              
tidb-ctl schemainmysql

Use Helm

Helmis a package management tool for Kubernetes. The installation steps are as follows:

Install the Helm client

Refer toHelm official documentationto install the Helm client.

If the server does not have access to the Internet, you need to download Helm on a machine with Internet access, and then copy it to the server. Here is an example of installing the Helm client3.4.1:


              
wget https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz tar zxvf helm-v3.4.1-linux-amd64.tar.gz

After decompression, you can see the following files:


              
linux-amd64/ linux-amd64/README.md linux-amd64/helm linux-amd64/LICENSE

Copy thelinux-amd64/helmfile to the server and place it under the/usr/local/bin/目录中。

Then executehelm verison. If the command outputs normally, the Helm installation is successful:


              
helm version

              
version.BuildInfo{Version:"v3.4.1", GitCommit:"c4e74854886b2efe3321e185578e6db9be0a6e29", GitTreeState:"clean", GoVersion:"go1.14.11"}

Configure the Helm repo

Kubernetes applications are packed as charts in Helm. PingCAP provides the following Helm charts for TiDB on Kubernetes:

  • tidb-operator: used to deploy TiDB Operator;
  • tidb-cluster: used to deploy TiDB clusters;
  • tidb-backup: used to back up or restore TiDB clusters;
  • tidb-lightning: used to import data into a TiDB cluster;
  • tidb-drainer: used to deploy TiDB Drainer;
  • tikv-importer: used to deploy TiKV Importer.

These charts are hosted in the Helm chart repositoryhttps://charts.pingcap.org/maintained by PingCAP. You can add this repository to your local server or computer using the following command:


              
helm repo add pingcap https://charts.pingcap.org/

Then you can search the chart provided by PingCAP using the following command:


              
helm search repo pingcap

              
NAME CHART VERSION APP VERSION DESCRIPTION pingcap/tidb-backup v1.5.0 A Helm chart for TiDB Backup or Restore pingcap/tidb-cluster v1.5.0 A Helm chart for TiDB Cluster pingcap/tidb-drainer v1.5.0 A Helm chart for TiDB Binlog drainer. pingcap/tidb-lightning v1.5.0 A Helm chart for TiDB Lightning pingcap/tidb-operator v1.5.0 v1.5.0 tidb-operator Helm chart for Kubernetes pingcap/tikv-importer v1.5.0 A Helm chart for TiKV Importer

When a new version of chart has been released, you can usehelm repo updateto update the repository cached locally:


              
helm repo update

Helm common operations

Common Helm operations includehelm install,helm upgrade, andhelm uninstall. Helm chart usually contains many configurable parameters which could be tedious to configure manually. For convenience, it is recommended that you configure using a YAML file. Based on the conventions in the Helm community, the YAML file used for Helm configuration is namedvalues.yamlin this document.

Before performing the deploy, upgrade and deploy, you can view the deployed applications viahelm ls:


              
helmls

When performing a deployment or upgrade, you must specify the chart name (chart-name) and the name for the deployed application (release-name). You can also specify one or multiplevalues.yamlfiles to configure charts. In addition, you can usechart-versionto specify the chart version (by default the latest GA is used). The steps in command line are as follows:

  • Install:

    
                    
    helm install${release_name} ${chart_name}--namespace=${namespace}--version=${chart_version}-f${values_file}
  • Upgrade (the upgrade can be either modifying thechart-versionto upgrade to the latest chart version, or editing thevalues.yamlfile to update the configuration):

    
                    
    helm upgrade${release_name} ${chart_name}--version=${chart_version}-f${values_file}
  • Delete:

    To delete the application deployed by Helm, run the following command:

    
                    
    helm uninstall${release_name}-n${namespace}

For more information on Helm, refer toHelm Documentation.

Use Helm chart offline

如果服务器has no Internet access, you cannot configure the Helm repo to install the TiDB Operator component and other applications. At this time, you need to download the chart file needed for cluster installation on a machine with Internet access, and then copy it to the server.

Use the following command to download the chart file required for cluster installation:


              
wget http://charts.pingcap.org/tidb-operator-v1.5.0.tgz wget http://charts.pingcap.org/tidb-drainer-v1.5.0.tgz wget http://charts.pingcap.org/tidb-lightning-v1.5.0.tgz

Copy these chart files to the server and decompress them. You can use these charts to install the corresponding components by running thehelm installcommand. Taketidb-operatoras an example:


              
tar zxvf tidb-operator.v1.5.0.tgz helm install${release_name}./tidb-operator --namespace=${namespace}

Use Terraform

Terraformis a Infrastructure as Code management tool. It enables users to define their own infrastructure in a manifestation style, based on which execution plans are generated to create or schedule real world compute resources. TiDB on Kubernetes use Terraform to create and manage TiDB clusters on public clouds.

Follow the steps inTerraform Documentationto install Terraform.

Download PDF Request docs changes Ask questions on Discord
Playground
New
One-stop & interactive experience of TiDB's capabilities WITHOUT registration.
Was this page helpful?
Products
TiDB
TiDB Dedicated
TiDB Serverless
Pricing
Get Demo
Get Started
©2023PingCAP. All Rights Reserved.