From 02dcb593ff422dfa01d09711244a9ccec9dfd49f Mon Sep 17 00:00:00 2001 From: csuzhangxc Date: Mon, 27 Nov 2023 09:10:16 +0000 Subject: [PATCH] zh, cn: remove tkctl --- en/TOC.md | 1 - en/maintain-a-kubernetes-node.md | 1 - en/network-issues.md | 14 +- en/tidb-operator-overview.md | 5 +- en/use-tkctl.md | 401 ------------------------------- zh/TOC.md | 1 - zh/network-issues.md | 14 +- zh/tidb-operator-overview.md | 5 +- zh/use-tkctl.md | 401 ------------------------------- 9 files changed, 10 insertions(+), 833 deletions(-) delete mode 100644 en/use-tkctl.md delete mode 100644 zh/use-tkctl.md diff --git a/en/TOC.md b/en/TOC.md index c936415c6c..9064917f12 100644 --- a/en/TOC.md +++ b/en/TOC.md @@ -117,7 +117,6 @@ - [Cheat Sheet](cheat-sheet.md) - [Required RBAC Rules](tidb-operator-rbac.md) - Tools - - [tkctl](use-tkctl.md) - [TiDB Toolkit](tidb-toolkit.md) - Configure - [Configure tidb-drainer Chart](configure-tidb-binlog-drainer.md) diff --git a/en/maintain-a-kubernetes-node.md b/en/maintain-a-kubernetes-node.md index e29c06fba6..2843b191be 100644 --- a/en/maintain-a-kubernetes-node.md +++ b/en/maintain-a-kubernetes-node.md @@ -13,7 +13,6 @@ This document introduces how to perform a temporary or long-term maintenance tas ## Prerequisites - [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/) -- [`tkctl`](use-tkctl.md) - [`jq`](https://stedolan.github.io/jq/download/) > **Note:** diff --git a/en/network-issues.md b/en/network-issues.md index 74cf0e172c..b37cb0c748 100644 --- a/en/network-issues.md +++ b/en/network-issues.md @@ -32,10 +32,10 @@ When you find some network connection issues among Pods from the log or monitori {{< copyable "shell-regular" >}} ```shell - tkctl debug -n ${namespace} ${pod_name} + kubectl -n ${namespace} exec -it ${pod_name} -- sh ``` - After the remote shell is started, use the `dig` command to diagnose the DNS resolution. If the DNS resolution is abnormal, refer to [Debugging DNS Resolution](https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/) for troubleshooting. + Use the `dig` command to diagnose the DNS resolution. If the DNS resolution is abnormal, refer to [Debugging DNS Resolution](https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/) for troubleshooting. {{< copyable "shell-regular" >}} @@ -53,15 +53,9 @@ When you find some network connection issues among Pods from the log or monitori - If the `ping` check fails, refer to [Debugging Kubernetes Networking](https://www.praqma.com/stories/debugging-kubernetes-networking/) for troubleshooting. - - If the `ping` check succeeds, continue to check whether the target port is open by using `telnet`: + - If the `ping` check succeeds, continue to check whether the target port is open by using `wget` or `curl`. - {{< copyable "shell-regular" >}} - - ```shell - telnet ${TARGET_IP} ${TARGET_PORT} - ``` - - If the `telnet` check fails, check whether the port corresponding to the Pod is correctly exposed and whether the port of the application is correctly configured: + If the `wget` or `curl` check fails, check whether the port corresponding to the Pod is correctly exposed and whether the port of the application is correctly configured: {{< copyable "shell-regular" >}} diff --git a/en/tidb-operator-overview.md b/en/tidb-operator-overview.md index 35b2d76e73..8f7ed58c2a 100644 --- a/en/tidb-operator-overview.md +++ b/en/tidb-operator-overview.md @@ -61,9 +61,6 @@ When a problem occurs and the cluster needs diagnosis, you can: + See [TiDB FAQs on Kubernetes](faq.md) for any available solution; + See [Troubleshoot TiDB on Kubernetes](tips.md) to shoot troubles. -TiDB on Kubernetes provides a dedicated command-line tool `tkctl` for cluster management and auxiliary diagnostics. Meanwhile, some of TiDB's tools are used differently on Kubernetes. You can: - -+ Use `tkctl` according to [`tkctl` Guide](use-tkctl.md ); -+ See [Tools on Kubernetes](tidb-toolkit.md) to understand how TiDB tools are used on Kubernetes. +Some of TiDB's tools are used differently on Kubernetes. You can see [Tools on Kubernetes](tidb-toolkit.md) to understand how TiDB tools are used on Kubernetes. Finally, when a new version of TiDB Operator is released, you can refer to [Upgrade TiDB Operator](upgrade-tidb-operator.md) to upgrade to the latest version. diff --git a/en/use-tkctl.md b/en/use-tkctl.md deleted file mode 100644 index b1e848b4d8..0000000000 --- a/en/use-tkctl.md +++ /dev/null @@ -1,401 +0,0 @@ ---- -title: TiDB Kubernetes Control User Guide -summary: Learn how to use the tkctl (TiDB Kubernetes Control) tool. -aliases: ['/docs/tidb-in-kubernetes/dev/use-tkctl/'] ---- - -# TiDB Kubernetes Control User Guide - -TiDB Kubernetes Control (`tkctl`) is a command line utility that is used for TiDB Operator to maintain and diagnose the TiDB cluster on Kubernetes. - -> **Note:** -> -> PingCAP is no longer maintaining `tkctl` from v1.1.x, some of the following functions may not be usable, please use the equivalent `kubectl` commands directly. - -## Installation - -To install `tkctl`, you can download the pre-built binary or build `tkctl` from source. - -### Download the latest pre-built binary - -- [MacOS](https://download.pingcap.org/tkctl-darwin-amd64-latest.tgz) -- [Linux](https://download.pingcap.org/tkctl-linux-amd64-latest.tgz) -- [Windows](https://download.pingcap.org/tkctl-windows-amd64-latest.tgz) - -After unzipping the downloaded file, you can add the `tkctl` executable file to your `PATH` to finish the installation. - -### Build from source - -Requirement: [Go](https://golang.org/) >= the 1.11 version or later - -{{< copyable "shell-regular" >}} - -```shell -git clone --depth=1 https://github.com/pingcap/tidb-operator.git && \ -GOOS= make cli &&\ -mv tkctl /usr/local/bin/tkctl -``` - -### Shell auto-completion - -You can configure the shell auto-completion for `tkctl` to simplify its usage. - -To configure the auto-completion for `BASH`, you need to first install the [bash-completion](https://github.com/scop/bash-completion) package, and configure with either of the two methods below: - -- Configure auto-completion in the current shell: - - {{< copyable "shell-regular" >}} - - ```shell - source <(tkctl completion bash) - ``` - -- Add auto-completion permanently to your bash shell: - - {{< copyable "shell-regular" >}} - - ```shell - echo "if hash tkctl 2>/dev/null; then source <(tkctl completion bash); fi" >> ~/.bashrc - ``` - -To configure the auto-completion for `ZSH`, you can choose from either of the two methods below: - -- Configure auto-completion in the current shell: - - {{< copyable "shell-regular" >}} - - ```shell - source <(tkctl completion zsh) - ``` - -- Add auto-completion permanently to your zsh shell: - - {{< copyable "shell-regular" >}} - - ```shell - echo "if hash tkctl 2>/dev/null; then source <(tkctl completion zsh); fi" >> ~/.zshrc - ``` - -### Kubernetes configuration - -`tkctl` reuses the `kubeconfig` file (the default location is `~/.kube/config`) to connect with the Kubernetes cluster. You can verify whether `kubeconfig` is correctly configured by using the following command: - -{{< copyable "shell-regular" >}} - -```shell -tkctl version -``` - -If the above command correctly outputs the version of TiDB Operator on the server side, then `kubeconfig` is correctly configured. - -## Commands - -### tkctl version - -This command is used to show the version of the local **tkctl** and **tidb-operator** installed in the target cluster. - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl version -``` - -``` -Client Version: v1.0.0-beta.1-p2-93-g6598b4d3e75705-dirty -TiDB Controller Manager Version: pingcap/tidb-operator:latest -TiDB Scheduler Version: pingcap/tidb-operator:latest -``` - -### tkctl list - -This command is used to list all installed TiDB clusters. - -| Flag | Abbreviation | Description | -| ----- | --------- | ----------- | -| --all-namespaces | -A | Whether to search all Kubernetes namespaces | -| --output | -o | The output format; you can choose from [default,json,yaml], and the default format is `default` | - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl list -A -``` - -``` -NAMESPACE NAME PD TIKV TIDB AGE -foo demo-cluster 3/3 3/3 2/2 11m -bar demo-cluster 3/3 3/3 1/2 11m -``` - -### tkctl use - -This command is used to specify the TiDB cluster that the current `tkctl` command operates on. After you specify a TiDB cluster by using this command, all commands that operates on a cluster will automatically select this cluster so the `--tidbcluster` option can be omitted. - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl use --namespace=foo demo-cluster -``` - -``` -Tidb cluster switched to foo/demo-cluster -``` - -### tkctl info - -This command is used to display information about the TiDB cluster. - -| Flag | Abbreviation | Description | -| ----- | --------- | ----------- | -| --tidb-cluster | -t | Specify a TiDB cluster; default to the TiDB cluster that is being used | - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl info -``` - -``` -Name: demo-cluster -Namespace: foo -CreationTimestamp: 2019-04-17 17:33:41 +0800 CST -Overview: - Phase Ready Desired CPU Memory Storage Version - ----- ----- ------- --- ------ ------- ------- - PD: Normal 3 3 200m 1Gi 1Gi pingcap/pd:v3.0.0-rc.1 - TiKV: Normal 3 3 1000m 2Gi 10Gi pingcap/tikv:v3.0.0-rc.1 - TiDB Upgrade 1 2 500m 1Gi pingcap/tidb:v3.0.0-rc.1 -Endpoints(NodePort): - - 172.16.4.158:31441 - - 172.16.4.155:31441 -``` - -### tkctl get [component] - -This is a group of commands that are used to get the details of TiDB cluster components. - -You can query the following components: `pd`, `tikv`, `tidb`, `volume` and `all` (to query all components). - -| Flag | Abbreviation | Description | -| ----- | --------- | ----------- | -| --tidb-cluster | -t | Specify a TiDB cluster; default to the TiDB cluster that is being used | -| --output | -o | The output format; you can choose from [default,json,yaml], and the default format is `default` | - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl get tikv -``` - -``` -NAME READY STATUS MEMORY CPU RESTARTS AGE NODE -demo-cluster-tikv-0 2/2 Running 2098Mi/4196Mi 2/2 0 3m19s 172.16.4.155 -demo-cluster-tikv-1 2/2 Running 2098Mi/4196Mi 2/2 0 4m8s 172.16.4.160 -demo-cluster-tikv-2 2/2 Running 2098Mi/4196Mi 2/2 0 4m45s 172.16.4.157 -``` - -{{< copyable "shell-regular" >}} - -```shell -tkctl get volume -``` - -``` -VOLUME CLAIM STATUS CAPACITY NODE LOCAL -local-pv-d5dad2cf tikv-demo-cluster-tikv-0 Bound 1476Gi 172.16.4.155 /mnt/disks/local-pv56 -local-pv-5ade8580 tikv-demo-cluster-tikv-1 Bound 1476Gi 172.16.4.160 /mnt/disks/local-pv33 -local-pv-ed2ffe50 tikv-demo-cluster-tikv-2 Bound 1476Gi 172.16.4.157 /mnt/disks/local-pv13 -local-pv-74ee0364 pd-demo-cluster-pd-0 Bound 1476Gi 172.16.4.155 /mnt/disks/local-pv46 -local-pv-842034e6 pd-demo-cluster-pd-1 Bound 1476Gi 172.16.4.158 /mnt/disks/local-pv74 -local-pv-e54c122a pd-demo-cluster-pd-2 Bound 1476Gi 172.16.4.156 /mnt/disks/local-pv72 -``` - -### tkctl debug [pod_name] - -This command is used to diagnose the Pods in a TiDB cluster. It launches a debug launcher Pod which then starts a debug container using the specified docker image on the same host of the target Pod. The container has necessary troubleshooting tools and shares the same namespaces with the container in the target Pod, so you can diagnose the target container by using various tools in the debug container. - -| Flag | Abbreviation | Description | -| ----- | --------- | ----------- | -| --image | | Specify the docker image used by the debug container; default to `pingcap/tidb-debug:lastest` | -| --launcher-image | | Specify the docker image for the debug launcher pod which is responsible for launching the debug container; default to `pingcap/debug-launcher:latest` | -| --container | -c | Select the container to be diagnosed; default to the first container of the target Pod | -| --docker-socket | | Specify the docker socket on the target node; default to `/var/run/docker.sock` | -| --privileged | | Whether to enable the [privileged](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) mode for the debug container | - -> **Note:** -> -> The default image of the debug container contains various troubleshooting tools, so the image size is relatively large. If you only need `pd-ctl` and `tidb-ctl`, you can specify using the `tidb-control` image by using the `--image=pingcap/tidb-control:latest` command line option. - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl debug demo-cluster-tikv-0 -``` - -{{< copyable "shell-regular" >}} - -```shell -ps -ef -``` - -Using tools like `GDB` and `perf` in the debug container requires special operations because of the difference in root filesystems of the target container and the debug container. - -#### GDB - -When you use GDB to debug the process in the target container, make sure you set the `program` option to the binary in the **target container**. Additionally, if you use images other than `tidb-debug` as the debug container or if the `pid` of the target process is not 1, you have to configure the location of dynamic libraries via the `set sysroot` command as follows: - -{{< copyable "shell-regular" >}} - -```shell -tkctl debug demo-cluster-tikv-0 -``` - -{{< copyable "shell-regular" >}} - -```shell -gdb /proc/${pid:-1}/root/tikv-server 1 -``` - -{{< copyable "shell-regular" >}} - -The `.gdbinit` pre-configured in the `tidb-debug` image will set `sysroot` to `/proc/1/root/` automatically. For this reason, you can omit this following step if you are using the `tidb-debug` image and the `pid` of the target process is 1. - -{{< copyable "shell-regular" >}} - -```shell -(gdb) set sysroot /proc/${pid}/root/ -``` - -Start debugging: - -{{< copyable "shell-regular" >}} - -```shell -(gdb) thread apply all bt -``` - -{{< copyable "shell-regular" >}} - -```shell -(gdb) info threads -``` - -#### Perf and flame graphs - -To use the `perf` command and the `run_flamegraph.sh` script properly, you must copy the program from the target container to the same location in the debug container: - -{{< copyable "shell-regular" >}} - -```shell -tkctl debug demo-cluster-tikv-0 -``` - -{{< copyable "shell-regular" >}} - -```shell -cp /proc/1/root/tikv-server / -``` - -{{< copyable "shell-regular" >}} - -```shell -./run_flamegraph.sh 1 -``` - -This script automatically uploads the generated flame graph (SVG format) to `transfer.sh`, and you can visit the link outputted by the script to download the flame graph. - -### tkctl ctop - -The complete form of the command is `tkctl ctop [pod_name | node/node_name ]`. - -This command is used to view the real-time monitoring stats of the target Pod or node in the cluster. Compared with `kubectl top`, `tkctl ctop` also provides network and disk stats, which are important for diagnosing problems in the TiDB cluster. - -| Flag | Abbreviation | Description | -| ----- | --------- | ----------- | -| --image | | Specify the docker image of ctop; default to `quay.io/vektorlab/ctop:0.7.2` | -| --docker-socket | | Specify the docker socket that ctop uses; default to `/var/run/docker.sock` | - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl ctop node/172.16.4.155 -``` - -{{< copyable "shell-regular" >}} - -```shell -tkctl ctop demo-cluster-tikv-0 -``` - -### tkctl help [command] - -This command is used to print help messages of the sub commands. - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl help debug -``` - -### tkctl options - -This command is used to view the global flags of `tkctl`. - -For example: - -{{< copyable "shell-regular" >}} - -```shell -tkctl options -``` - -``` -The following options can be passed to any command: - - --alsologtostderr=false: log to standard error as well as files - --as='': Username to impersonate for the operation - --as-group=[]: Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --cache-dir='/Users/alei/.kube/http-cache': Default HTTP cache directory - --certificate-authority='': Path to a cert file for the certificate authority - --client-certificate='': Path to a client certificate file for TLS - --client-key='': Path to a client key file for TLS - --cluster='': The name of the kubeconfig cluster to use - --context='': The name of the kubeconfig context to use - --insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will -make your HTTPS connections insecure - --kubeconfig='': Path to the kubeconfig file to use for CLI requests. - --log_backtrace_at=:0: when logging hits line file:N, emit a stack trace - --log_dir='': If non-empty, write log files in this directory - --logtostderr=true: log to standard error instead of files - -n, --namespace='': If present, the namespace scope for this CLI request - --request-timeout='0': The length of time to wait before giving up on a single server request. Non-zero values -should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. - -s, --server='': The address and port of the Kubernetes API server - --stderrthreshold=2: logs at or above this threshold go to stderr - -t, --tidbcluster='': Tidb cluster name - --token='': Bearer token for authentication to the API server - --user='': The name of the kubeconfig user to use - -v, --v=0: log level for V logs - --vmodule=: comma-separated list of pattern=N settings for file-filtered logging -``` - -These options are mainly used to connect with the Kubernetes cluster and two commonly used options among them are as follows: - -- `--context`: specify the target Kubernetes cluster -- `--namespace`: specify the Kubernetes namespace diff --git a/zh/TOC.md b/zh/TOC.md index 11c2973211..10e964f28c 100644 --- a/zh/TOC.md +++ b/zh/TOC.md @@ -117,7 +117,6 @@ - [Cheat Sheet](cheat-sheet.md) - [TiDB Operator RBAC 规则](tidb-operator-rbac.md) - 工具 - - [tkctl](use-tkctl.md) - [TiDB Toolkit](tidb-toolkit.md) - 配置 - [tidb-drainer chart 配置](configure-tidb-binlog-drainer.md) diff --git a/zh/network-issues.md b/zh/network-issues.md index 1029a929e3..061885dd21 100644 --- a/zh/network-issues.md +++ b/zh/network-issues.md @@ -33,10 +33,10 @@ aliases: ['/docs-cn/tidb-in-kubernetes/dev/network-issues/'] {{< copyable "shell-regular" >}} ``` - tkctl debug -n ${namespace} ${pod_name} + kubectl -n ${namespace} exec -it ${pod_name} -- sh ``` - 远端 shell 启动后,使用 `dig` 命令诊断 DNS 解析,假如 DNS 解析异常,请参照[诊断 Kubernetes DNS 解析](https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/)进行故障排除: + 使用 `dig` 命令诊断 DNS 解析,假如 DNS 解析异常,请参照[诊断 Kubernetes DNS 解析](https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/)进行故障排除: {{< copyable "shell-regular" >}} @@ -54,15 +54,9 @@ aliases: ['/docs-cn/tidb-in-kubernetes/dev/network-issues/'] 假如 ping 检查失败,请参照[诊断 Kubernetes 网络](https://www.praqma.com/stories/debugging-kubernetes-networking/)进行故障排除。 - 假如 ping 检查正常,继续使用 `telnet` 检查目标端口是否打开: + 假如 ping 检查正常,继续使用 `wget` 或 `curl` 检查目标端口是否打开。 - {{< copyable "shell-regular" >}} - - ```shell - telnet ${TARGET_IP} ${TARGET_PORT} - ``` - - 假如 `telnet` 检查失败,则需要验证 Pod 的对应端口是否正确暴露以及应用的端口是否配置正确: + 假如 `wget` 或 `curl` 检查失败,则需要验证 Pod 的对应端口是否正确暴露以及应用的端口是否配置正确: {{< copyable "shell-regular" >}} diff --git a/zh/tidb-operator-overview.md b/zh/tidb-operator-overview.md index fb34f208df..84b093d8d5 100644 --- a/zh/tidb-operator-overview.md +++ b/zh/tidb-operator-overview.md @@ -63,9 +63,6 @@ TiDB Operator 提供了多种方式来部署 Kubernetes 上的 TiDB 集群: + 查阅 [Kubernetes 上的 TiDB FAQ](faq.md) 寻找是否存在现成的解决办法; + 参考 [Kubernetes 上的 TiDB 故障诊断](tips.md)解决故障。 -Kubernetes 上的 TiDB 提供了专用的命令行工具 `tkctl` 用于集群管理和辅助诊断,同时,在 Kubernetes 上,TiDB 的部分生态工具的使用方法也有所不同,你可以: - -+ 参考 [`tkctl` 使用指南](use-tkctl.md) 来使用 `tkctl`; -+ 参考 [Kubernetes 上的 TiDB 相关工具使用指南](tidb-toolkit.md)来了解 TiDB 生态工具在 Kubernetes 上的使用方法。 +在 Kubernetes 上,TiDB 的部分生态工具的使用方法也有所不同,你可以参考 [Kubernetes 上的 TiDB 相关工具使用指南](tidb-toolkit.md)来了解 TiDB 生态工具在 Kubernetes 上的使用方法。 最后,当 TiDB Operator 发布新版本时,你可以参考[升级 TiDB Operator](upgrade-tidb-operator.md) 进行版本更新。 diff --git a/zh/use-tkctl.md b/zh/use-tkctl.md deleted file mode 100644 index a7615d5034..0000000000 --- a/zh/use-tkctl.md +++ /dev/null @@ -1,401 +0,0 @@ ---- -title: tkctl 使用指南 -summary: 介绍如何使用 tkctl 命令行工具来运维集群和诊断集群问题。 -aliases: ['/docs-cn/tidb-in-kubernetes/dev/use-tkctl/'] ---- - -# tkctl 使用指南 - -`tkctl` (TiDB Kubernetes Control) 是为 TiDB on Kubernetes 设计的命令行工具,用于运维集群和诊断集群问题。 - -> **注意:** -> -> PingCAP 从 v1.1.x 开始不再维护 `tkctl`,以下部分功能可能不可用,请直接使用对应的 `kubectl` 命令。 - -## 安装 - -安装 `tkctl` 时,可以直接下载预编译的可执行文件,也可以自行从源码进行编译。 - -### 下载预编译的可执行文件 - -- [MacOS](https://download.pingcap.org/tkctl-darwin-amd64-latest.tgz) -- [Linux](https://download.pingcap.org/tkctl-linux-amd64-latest.tgz) -- [Windows](https://download.pingcap.org/tkctl-windows-amd64-latest.tgz) - -下载解压后,将 `tkctl` 可执行文件加入到可执行文件路径 (`PATH`) 中即完成安装。 - -### 源码编译 - -要求:[Go](https://golang.org/) 版本 1.11 及以上 - -{{< copyable "shell-regular" >}} - -```shell -git clone https://github.com/pingcap/tidb-operator.git && \ -GOOS=${YOUR_GOOS} make cli && \ -mv tkctl /usr/local/bin/tkctl -``` - -## 命令自动补全 - -你可以配置 `tkctl` 的自动补全以简化使用。 - -为 BASH 配置自动补全(需要预先安装 [bash-completion](https://github.com/scop/bash-completion))的方法如下。 - -在当前 shell 中设置自动补全: - -{{< copyable "shell-regular" >}} - -```shell -source <(tkctl completion bash) -``` - -永久设置自动补全: - -{{< copyable "shell-regular" >}} - -```shell -echo "if hash tkctl 2>/dev/null; then source <(tkctl completion bash); fi" >> ~/.bashrc -``` - -为 ZSH 配置自动补全的方法如下。 - -在当前 shell 中设置自动补全: - -{{< copyable "shell-regular" >}} - -```shell -source <(tkctl completion zsh) -``` - -永久设置自动补全: - -{{< copyable "shell-regular" >}} - -```shell -echo "if hash tkctl 2>/dev/null; then source <(tkctl completion zsh); fi" >> ~/.zshrc -``` - -## Kubernetes 配置 - -`tkctl` 复用了 `kubeconfig` 文件(默认位置是 `~/.kube/config`)来连接 Kubernetes 集群。你可以通过下面的命令来验证 `kubeconfig` 是否设置正确: - -{{< copyable "shell-regular" >}} - -```shell -tkctl version -``` - -假如上面的命令正确输出服务端的 TiDB Operator 版本,则 `kubeconfig` 配置正确。 - -## 所有命令 - -### tkctl version - -该命令用于展示本地 **tkctl** 和集群中 **tidb-operator** 的版本: - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl version -``` - -``` -Client Version: v1.0.0-beta.1-p2-93-g6598b4d3e75705-dirty -TiDB Controller Manager Version: pingcap/tidb-operator:latest -TiDB Scheduler Version: pingcap/tidb-operator:latest -``` - -### tkctl list - -该命令用于列出所有已安装的 TiDB 集群: - -| 参数 | 缩写 | 说明 | -| ----- | --------- | ----------- | -| --all-namespaces | -A | 是否查询所有的 Kubernetes Namespace | -| --output | -o | 输出格式,可选值有 [default,json,yaml],默认值为 `default` | - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl list -A -``` - -``` -NAMESPACE NAME PD TIKV TIDB AGE -foo demo-cluster 3/3 3/3 2/2 11m -bar demo-cluster 3/3 3/3 1/2 11m -``` - -### tkctl use - -该命令用于指定当前 `tkctl` 操作的 TiDB 集群,在使用该命令设置当前操作的 TiDB 集群后,所有针对集群的操作命令会自动选定该集群,从而可以略去 `--tidbcluster` 参数。 - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl use --namespace=foo demo-cluster -``` - -``` -Tidb cluster switched to foo/demo-cluster -``` - -### tkctl info - -该命令用于展示 TiDB 集群的信息。 - -| 参数 | 缩写 | 说明 | -| ----- | --------- | ----------- | -| --tidb-cluster | -t | 指定 TiDB 集群,默认为当前使用的 TiDB 集群 | - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl info -``` - -``` -Name: demo-cluster -Namespace: foo -CreationTimestamp: 2019-04-17 17:33:41 +0800 CST -Overview: - Phase Ready Desired CPU Memory Storage Version - ----- ----- ------- --- ------ ------- ------- - PD: Normal 3 3 200m 1Gi 1Gi pingcap/pd:v3.0.0-rc.1 - TiKV: Normal 3 3 1000m 2Gi 10Gi pingcap/tikv:v3.0.0-rc.1 - TiDB Upgrade 1 2 500m 1Gi pingcap/tidb:v3.0.0-rc.1 -Endpoints(NodePort): - - 172.16.4.158:31441 - - 172.16.4.155:31441 -``` - -### tkctl get [component] - -该命令用于获取 TiDB 集群中组件的详细信息。 - -可选的组件 (`component`) 有: `pd`、`tikv`、`tidb`、`volume` 和 `all`(用于同时查询所有组件)。 - -| 参数 | 缩写 | 说明 | -| ----- | --------- | ----------- | -| --tidb-cluster | -t | 指定 TiDB 集群,默认为当前使用的 TiDB 集群 | -| --output | -o | 输出格式,可选值有 `default`、`json` 和 `yaml`,默认值为 `default` | - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl get tikv -``` - -``` -NAME READY STATUS MEMORY CPU RESTARTS AGE NODE -demo-cluster-tikv-0 2/2 Running 2098Mi/4196Mi 2/2 0 3m19s 172.16.4.155 -demo-cluster-tikv-1 2/2 Running 2098Mi/4196Mi 2/2 0 4m8s 172.16.4.160 -demo-cluster-tikv-2 2/2 Running 2098Mi/4196Mi 2/2 0 4m45s 172.16.4.157 -``` - -{{< copyable "shell-regular" >}} - -```shell -tkctl get volume -``` - -``` -VOLUME CLAIM STATUS CAPACITY NODE LOCAL -local-pv-d5dad2cf tikv-demo-cluster-tikv-0 Bound 1476Gi 172.16.4.155 /mnt/disks/local-pv56 -local-pv-5ade8580 tikv-demo-cluster-tikv-1 Bound 1476Gi 172.16.4.160 /mnt/disks/local-pv33 -local-pv-ed2ffe50 tikv-demo-cluster-tikv-2 Bound 1476Gi 172.16.4.157 /mnt/disks/local-pv13 -local-pv-74ee0364 pd-demo-cluster-pd-0 Bound 1476Gi 172.16.4.155 /mnt/disks/local-pv46 -local-pv-842034e6 pd-demo-cluster-pd-1 Bound 1476Gi 172.16.4.158 /mnt/disks/local-pv74 -local-pv-e54c122a pd-demo-cluster-pd-2 Bound 1476Gi 172.16.4.156 /mnt/disks/local-pv72 -``` - -### tkctl debug [pod_name] - -该命令用于诊断 TiDB 集群中的 Pod。 - -实际使用时,该命令会在目标 Pod 的宿主机上启动 debug launcher Pod 并以指定镜像启动一个 debug 容器,该容器会与目标 Pod 中的容器共享 namespace,因此可以无缝使用 debug 容器中的各种工具对目标容器进行诊断。 - -| 参数 | 缩写 | 描述 | -| ----- | --------- | ----------- | -| --image | | 指定 debug 容器使用的镜像,默认为 `pingcap/tidb-debug:latest` | -| --launcher-image | | 指定启动 debug 容器的 debug launcher Pod 使用的镜像,默认为 `pingcap/debug-launcher:latest` | -| --container | -c | 选择需要诊断的容器,默认为 Pod 定义中的第一个容器 | -| --docker-socket | | 指定目标节点上的 Docker Socket,默认为 `/var/run/docker.sock` | -| --privileged | | 是否为 debug 容器开启 [privileged](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) 模式 | - -> **注意:** -> -> Debug 容器使用的默认镜像包含了绝大多数的诊断工具,因此体积较大,假如只需要 `pd-ctl` 和 `tidb-ctl`,可以使用 `--image=pingcap/tidb-control:latest` 来指定使用 `tidb-control` 镜像。 - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl debug demo-cluster-tikv-0 -``` - -{{< copyable "shell-regular" >}} - -```shell -ps -ef -``` - -由于 debug 容器和目标容器拥有不同的根文件系统,在 `tidb-debug` 容器中使用 GDB 和 perf 等工具时可能会碰到一些问题,下面将补充说明如何解决这些问题。 - -#### GDB - -使用 GDB 调试目标容器中的进程时,需要将 `program` 参数设置为目标容器中的可执行文件。假如是在 `tidb-debug` 以外的其它 debug 容器中进行调试,或者调试的目标进行 pid 不为 1,则需要使用 `set sysroot` 命令调整动态链接库的加载位置。操作如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl debug demo-cluster-tikv-0 -``` - -{{< copyable "shell-regular" >}} - -```shell -gdb /proc/${pid:-1}/root/tikv-server 1 -``` - -`tidb-debug` 中预配置的 `.gdbinit` 会将 `sysroot` 设置为 `/proc/1/root/`,因此在 `tidb-debug` 中,假如目标容器的 pid 为 1,则下面的命令可以省略。 - -{{< copyable "shell-regular" >}} - -```shell -(gdb) set sysroot /proc/${pid}/root/ -``` - -开始调试: - -{{< copyable "shell-regular" >}} - -```shell -(gdb) thread apply all bt -``` - -{{< copyable "shell-regular" >}} - -```shell -(gdb) info threads -``` - -#### Perf 以及火焰图 - -使用 `perf` 命令和 `run-flamegraph.sh` 脚本时,需要将目标容器的可执行文件拷贝到 Debug 容器中: - -{{< copyable "shell-regular" >}} - -```shell -tkctl debug demo-cluster-tikv-0 -``` - -{{< copyable "shell-regular" >}} - -```shell -cp /proc/1/root/tikv-server / -``` - -{{< copyable "shell-regular" >}} - -```shell -./run_flamegraph.sh 1 -``` - -该脚本会自动将生成的火焰图(SVG 格式)上传至 transfer.sh,通过访问脚本输出的链接即可下载火焰图。 - -### tkctl ctop - -命令的完整形式:`tkctl ctop [pod_name | node/node_name ]`。 - -该命令用于查看集群中 Pod 或 Node 的实时监控信息,和 `kubectl top` 相比,`tkctl ctop` 还会展示网络和磁盘的使用信息。 - -| 参数 | 简写 | 描述 | -| ----- | --------- | ----------- | -| --image | | 指定 ctop 的镜像,默认为 `quay.io/vektorlab/ctop:0.7.2` | -| --docker-socket | | 指定 ctop 使用的 Docker Socket,默认为 `/var/run/docker.sock` | - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl ctop demo-cluster-tikv-0 -``` - -{{< copyable "shell-regular" >}} - -```shell -tkctl ctop node/172.16.4.155 -``` - -### tkctl help [command] - -该命令用于展示各个子命令的帮助信息。 - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl help debug -``` - -### tkctl options - -该命令用于展示 `tkctl` 的所有的全局参数。 - -示例如下: - -{{< copyable "shell-regular" >}} - -```shell -tkctl options -``` - -``` -The following options can be passed to any command: - - --alsologtostderr=false: log to standard error as well as files - --as='': Username to impersonate for the operation - --as-group=[]: Group to impersonate for the operation, this flag can be repeated to specify multiple groups. - --cache-dir='/Users/alei/.kube/http-cache': Default HTTP cache directory - --certificate-authority='': Path to a cert file for the certificate authority - --client-certificate='': Path to a client certificate file for TLS - --client-key='': Path to a client key file for TLS - --cluster='': The name of the kubeconfig cluster to use - --context='': The name of the kubeconfig context to use - --insecure-skip-tls-verify=false: If true, the server's certificate will not be checked for validity. This will -make your HTTPS connections insecure - --kubeconfig='': Path to the kubeconfig file to use for CLI requests. - --log_backtrace_at=:0: when logging hits line file:N, emit a stack trace - --log_dir='': If non-empty, write log files in this directory - --logtostderr=true: log to standard error instead of files - -n, --namespace='': If present, the namespace scope for this CLI request - --request-timeout='0': The length of time to wait before giving up on a single server request. Non-zero values -should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. - -s, --server='': The address and port of the Kubernetes API server - --stderrthreshold=2: logs at or above this threshold go to stderr - -t, --tidbcluster='': Tidb cluster name - --token='': Bearer token for authentication to the API server - --user='': The name of the kubeconfig user to use - -v, --v=0: log level for V logs - --vmodule=: comma-separated list of pattern=N settings for file-filtered logging -``` - -这些参数主要用于指定如何连接 Kubernetes 集群,其中最常用的参数是: - -- `--context`:指定目标 Kubernetes 集群 -- `--namespace`:指定 Namespace