Skip to content

Commit

Permalink
en, zh: move tidb-operator architecture section to a new page (#388)
Browse files Browse the repository at this point in the history
* Move tidb-operator architecture section to a new page

* Apply suggestions from code review

Co-authored-by: Ran <huangran@pingcap.com>

* Apply suggestions from code review

Co-authored-by: Ran <huangran@pingcap.com>

Co-authored-by: Ran <huangran@pingcap.com>
  • Loading branch information
cofyc and ran-huang authored Jun 28, 2020
1 parent 5360c22 commit a5e9c99
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 66 deletions.
1 change: 1 addition & 0 deletions en/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
- [FAQs](faq.md)
+ Reference
+ Architecture
- [TiDB Operator](architecture.md)
- [TiDB Scheduler](tidb-scheduler.md)
- [Advanced StatefulSet Controller](advanced-statefulset.md)
- [Admission Controller](enable-admission-webhook.md)
Expand Down
48 changes: 48 additions & 0 deletions en/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: TiDB Operator Architecture
summary: Learn the architecture of TiDB Operator and how it works.
category: reference
---

# TiDB Operator Architecture

This document describes the architecture of TiDB Operator and how it works.

## Architecture

The following diagram is an overview of the architecture of TiDB Operator.

![TiDB Operator Overview](/media/tidb-operator-overview-1.1.png)

`TidbCluster`, `TidbMonitor`, `TidbInitializer`, `Backup`, `Restore`, `BackupSchedule`, and `TidbClusterAutoScaler` are custom resources defined by CRD (`CustomResourceDefinition`).

* `TidbCluster` describes the desired state of the TiDB cluster.
* `TidbMonitor` describes the monitoring components of the TiDB cluster.
* `TidbInitializer` describes the desired initialization Job of the TiDB cluster.
* `Backup` describes the desired backup of the TiDB cluster.
* `Restore` describes the desired restoration of the TiDB cluster.
* `BackupSchedule` describes the scheduled backup of the TiDB cluster.
* `TidbClusterAutoScaler` describes the automatic scaling of the TiDB cluster.

The following components are responsible for the orchestration and scheduling logic in a TiDB cluster:

* `tidb-controller-manager` is a set of custom controllers in Kubernetes. These controllers constantly compare the desired state recorded in the `TidbCluster` object with the actual state of the TiDB cluster. They adjust the resources in Kubernetes to drive the TiDB cluster to meet the desired state and complete the corresponding control logic according to other CRs;
* `tidb-scheduler` is a Kubernetes scheduler extension that injects the TiDB specific scheduling policies to the Kubernetes scheduler;
* `tidb-admission-webhook` is a dynamic admission controller in Kubernetes, which completes the modification, verification, operation and maintenance of Pod, StatefulSet and other related resources.

In addition, TiDB Operator also provides `tkctl`, the command-line interface for TiDB clusters in Kubernetes. It is used for cluster operations and troubleshooting cluster issues.

## Control flow

The following diagram is the analysis of the control flow of TiDB Operator. Starting from TiDB Operator v1.1, the TiDB cluster, monitoring, initialization, backup, and other components are deployed and managed using CR.

![TiDB Operator Control Flow](/media/tidb-operator-control-flow-1.1.png)

The overall control flow is described as follows:

1. The user creates a `TidbCluster` object and other CR objects through kubectl, such as `TidbMonitor`;
2. TiDB Operator watches `TidbCluster` and other related objects, and constantly adjust the `StatefulSet`, `Deployment`, `Service`, and other objects of PD, TiKV, TiDB, Monitor or other components based on the actual state of the cluster;
3. Kubernetes' native controllers create, update, or delete the corresponding `Pod` based on objects such as `StatefulSet`, `Deployment`, and `Job`;
4. In the `Pod` declaration of PD, TiKV, and TiDB, the `tidb-scheduler` scheduler is specified. `tidb-scheduler` applies the specific scheduling logic of TiDB when scheduling the corresponding `Pod`.

Based on the above declarative control flow, TiDB Operator automatically performs health check and fault recovery for the cluster nodes. You can easily modify the `TidbCluster` object declaration to perform operations such as deployment, upgrade and scaling.
33 changes: 0 additions & 33 deletions en/tidb-operator-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,6 @@ The corresponding relationship between TiDB Operator and TiDB versions is as fol
| v1.1 | v3.0, v3.1, v4.0 |
| dev | v3.0, v3.1, v4.0, dev |

## TiDB Operator architecture

![TiDB Operator Overview](/media/tidb-operator-overview-1.1.png)

`TidbCluster`, `TidbMonitor`, `TidbInitializer`, `Backup`, `Restore`, `BackupSchedule`, and `TidbClusterAutoScaler` are custom resources defined by CRD (`CustomResourceDefinition`).

* `TidbCluster` describes the desired state of the TiDB cluster.
* `TidbMonitor` describes the monitoring components of the TiDB cluster.
* `TidbInitializer` describes the desired initialization Job of the TiDB cluster.
* `Backup` describes the desired backup of the TiDB cluster.
* `Restore` describes the desired restoration of the TiDB cluster.
* `BackupSchedule` describes the scheduled backup of the TiDB cluster.
* `TidbClusterAutoScaler` describes the automatic scaling of the TiDB cluster.

The following components are responsible for the orchestration and scheduling logic in a TiDB cluster:

* `tidb-controller-manager` is a set of custom controllers in Kubernetes. These controllers constantly compare the desired state recorded in the `TidbCluster` object with the actual state of the TiDB cluster. They adjust the resources in Kubernetes to drive the TiDB cluster to meet the desired state and complete the corresponding control logic according to other CRs;
* `tidb-scheduler` is a Kubernetes scheduler extension that injects the TiDB specific scheduling policies to the Kubernetes scheduler;
* `tidb-admission-webhook` is a dynamic admission controller in Kubernetes, which completes the modification, verification, operation and maintenance of Pod, StatefulSet and other related resources.

In addition, TiDB Operator also provides `tkctl`, the command-line interface for TiDB clusters in Kubernetes. It is used for cluster operations and troubleshooting cluster issues.

![TiDB Operator Control Flow](/media/tidb-operator-control-flow-1.1.png)

The diagram above is the analysis of the control flow of TiDB Operator. Starting from TiDB Operator v1.1, the TiDB cluster, monitoring, initialization, backup, and other components are deployed and managed using CR. The overall control flow is described as follows:

1. The user creates a `TidbCluster` object and other CR objects through kubectl, such as `TidbMonitor`;
2. TiDB Operator watches `TidbCluster` and other related objects, and constantly adjust the `StatefulSet`, `Deployment`, `Service`, and other objects of PD, TiKV, TiDB, Monitor or other components based on the actual state of the cluster;
3. Kubernetes' native controllers create, update, or delete the corresponding `Pod` based on objects such as `StatefulSet`, `Deployment`, and `Job`;
4. In the `Pod` declaration of PD, TiKV, and TiDB, the `tidb-scheduler` scheduler is specified. `tidb-scheduler` applies the specific scheduling logic of TiDB when scheduling the corresponding `Pod`.

Based on the above declarative control flow, TiDB Operator automatically performs health check and fault recovery for the cluster nodes. You can easily modify the `TidbCluster` object declaration to perform operations such as deployment, upgrade and scaling.

## Manage TiDB clusters using TiDB Operator

TiDB Operator provides several ways to deploy TiDB clusters in Kubernetes:
Expand Down
1 change: 1 addition & 0 deletions zh/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- [常见问题](faq.md)
+ 参考
+ 架构
- [TiDB Operator 架构](architecture.md)
- [TiDB Scheduler 扩展调度器](tidb-scheduler.md)
- [增强型 StatefulSet 控制器](advanced-statefulset.md)
- [准入控制器](enable-admission-webhook.md)
Expand Down
48 changes: 48 additions & 0 deletions zh/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: TiDB Operator 架构
summary: 了解 TiDB Operator 架构及其工作原理。
category: reference
---

# TiDB Operator 架构

本文档介绍 TiDB Operator 的架构及其工作原理。

## 架构

下图是 TiDB Operator 的架构概览。

![TiDB Operator Overview](/media/tidb-operator-overview-1.1.png)

其中,`TidbCluster``TidbMonitor``TidbInitializer``Backup``Restore``BackupSchedule``TidbClusterAutoScaler` 是由 CRD(`CustomResourceDefinition`)定义的自定义资源:

* `TidbCluster` 用于描述用户期望的 TiDB 集群
* `TidbMonitor` 用于描述用户期望的 TiDB 集群监控组件
* `TidbInitializer` 用于描述用户期望的 TiDB 集群初始化 Job
* `Backup` 用于描述用户期望的 TiDB 集群备份
* `Restore` 用于描述用户期望的 TiDB 集群恢复
* `BackupSchedule` 用于描述用户期望的 TiDB 集群周期性备份
* `TidbClusterAutoScaler` 用于描述用户期望的 TiDB 集群自动伸缩

TiDB 集群的编排和调度逻辑则由下列组件负责:

* `tidb-controller-manager` 是一组 Kubernetes 上的自定义控制器。这些控制器会不断对比 `TidbCluster` 对象中记录的期望状态与 TiDB 集群的实际状态,并调整 Kubernetes 中的资源以驱动 TiDB 集群满足期望状态,并根据其他 CR 完成相应的控制逻辑;
* `tidb-scheduler` 是一个 Kubernetes 调度器扩展,它为 Kubernetes 调度器注入 TiDB 集群特有的调度逻辑。
* `tidb-admission-webhook` 是一个 Kubernetes 动态准入控制器,完成 Pod、StatefulSet 等相关资源的修改、验证与运维。

此外,TiDB Operator 还提供了命令行接口 `tkctl` 用于运维集群和诊断集群问题。

## 流程解析

下图是 TiDB Operator 的控制流程解析。从 TiDB Operator v1.1 开始,TiDB 集群、监控、初始化、备份等组件,都通过 CR 进行部署、管理。

![TiDB Operator Control Flow](/media/tidb-operator-control-flow-1.1.png)

整体的控制流程如下:

1. 用户通过 kubectl 创建 `TidbCluster` 和其他 CR 对象,比如 `TidbMonitor` 等;
2. TiDB Operator 会 watch `TidbCluster` 以及其它相关对象,基于集群的实际状态不断调整 PD、TiKV、TiDB 或者 Monitor 等组件的 `StatefulSet``Deployment``Service` 等对象;
3. Kubernetes 的原生控制器根据 `StatefulSet``Deployment``Job` 等对象创建更新或删除对应的 `Pod`
4. PD、TiKV、TiDB 的 `Pod` 声明中会指定使用 `tidb-scheduler` 调度器,`tidb-scheduler` 会在调度对应 `Pod` 时应用 TiDB 的特定调度逻辑。

基于上述的声明式控制流程,TiDB Operator 能够自动进行集群节点健康检查和故障恢复。部署、升级、扩缩容等操作也可以通过修改 `TidbCluster` 对象声明“一键”完成。
33 changes: 0 additions & 33 deletions zh/tidb-operator-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,6 @@ TiDB Operator 与适用的 TiDB 版本的对应关系如下:
| v1.1 | v3.0, v3.1, v4.0 |
| dev | v3.0, v3.1, v4.0, dev |

## TiDB Operator 整体架构

![TiDB Operator Overview](/media/tidb-operator-overview-1.1.png)

其中,`TidbCluster``TidbMonitor``TidbInitializer``Backup``Restore``BackupSchedule``TidbClusterAutoScaler` 是由 CRD(`CustomResourceDefinition`)定义的自定义资源:

* `TidbCluster` 用于描述用户期望的 TiDB 集群
* `TidbMonitor` 用于描述用户期望的 TiDB 集群监控组件
* `TidbInitializer` 用于描述用户期望的 TiDB 集群初始化 Job
* `Backup` 用于描述用户期望的 TiDB 集群备份
* `Restore` 用于描述用户期望的 TiDB 集群恢复
* `BackupSchedule` 用于描述用户期望的 TiDB 集群周期性备份
* `TidbClusterAutoScaler` 用于描述用户期望的 TiDB 集群自动伸缩

TiDB 集群的编排和调度逻辑则由下列组件负责:

* `tidb-controller-manager` 是一组 Kubernetes 上的自定义控制器。这些控制器会不断对比 `TidbCluster` 对象中记录的期望状态与 TiDB 集群的实际状态,并调整 Kubernetes 中的资源以驱动 TiDB 集群满足期望状态,并根据其他 CR 完成相应的控制逻辑;
* `tidb-scheduler` 是一个 Kubernetes 调度器扩展,它为 Kubernetes 调度器注入 TiDB 集群特有的调度逻辑。
* `tidb-admission-webhook` 是一个 Kubernetes 动态准入控制器,完成 Pod、StatefulSet 等相关资源的修改、验证与运维。

此外,TiDB Operator 还提供了命令行接口 `tkctl` 用于运维集群和诊断集群问题。

![TiDB Operator Control Flow](/media/tidb-operator-control-flow-1.1.png)

上图是 TiDB Operator 的控制流程解析。从 TiDB Operator v1.1 开始,TiDB 集群、监控、初始化、备份等组件,都通过 CR 进行部署、管理。整体的控制流程如下:

1. 用户通过 kubectl 创建 `TidbCluster` 和其他 CR 对象,比如 `TidbMonitor` 等;
2. TiDB Operator 会 watch `TidbCluster` 以及其它相关对象,基于集群的实际状态不断调整 PD、TiKV、TiDB 或者 Monitor 等组件的 `StatefulSet``Deployment``Service` 等对象;
3. Kubernetes 的原生控制器根据 `StatefulSet``Deployment``Job` 等对象创建更新或删除对应的 `Pod`
4. PD、TiKV、TiDB 的 `Pod` 声明中会指定使用 `tidb-scheduler` 调度器,`tidb-scheduler` 会在调度对应 `Pod` 时应用 TiDB 的特定调度逻辑。

基于上述的声明式控制流程,TiDB Operator 能够自动进行集群节点健康检查和故障恢复。部署、升级、扩缩容等操作也可以通过修改 `TidbCluster` 对象声明“一键”完成。

## 使用 TiDB Operator 管理 TiDB 集群

TiDB Operator 提供了多种方式来部署 Kubernetes 上的 TiDB 集群:
Expand Down

0 comments on commit a5e9c99

Please sign in to comment.