File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 2121 - 基于快照的备份和恢复
2222 - 运维
2323 - [ 查看 TiDB 日志] ( view-logs.md )
24+ - [ 重启 TiDB 集群] ( restart-a-tidb-cluster.md )
2425 - [ 销毁 TiDB 集群] ( destroy-a-tidb-cluster.md )
2526 - 为 TiDB 集群更换节点
2627 - 灾难恢复
Original file line number Diff line number Diff line change 1+ ---
2+ title : 重启 Kubernetes 上的 TiDB 集群
3+ summary : 了解如何重启 Kubernetes 集群上的 TiDB 集群,包括优雅滚动重启 TiDB 集群中某个组件的所有 Pod,以及单独重启某个 Pod。
4+ ---
5+
6+ # 重启 Kubernetes 上的 TiDB 集群
7+
8+ 在使用 TiDB 集群的过程中,如果某个 Pod 存在内存泄漏等问题,可能需要重启集群。本文介绍如何优雅滚动重启 TiDB 集群中某个组件的所有 Pod,或单独优雅重启某个 Pod。
9+
10+ > ** 警告:**
11+ >
12+ > 在生产环境中,强烈建议不要强制删除 TiDB 集群的 Pod。虽然 TiDB Operator 会自动重新创建被删除的 Pod,但这仍可能会导致部分访问 TiDB 集群的请求失败。
13+
14+ ## 优雅滚动重启某个组件的所有 Pod
15+
16+ 要优雅滚动重启某个组件(例如 PD、TiKV 或 TiDB)的所有 Pod,需要修改该组件对应的 Component Group Custom Resource (CR) 配置,在 ` .spec.template.metadata ` 部分添加 ` pingcap.com/restartedAt ` 的 label 或 annotation,并将其值设置为一个保证幂等性的字符串,例如当前时间。
17+
18+ 以下示例展示如何为 PD 组件添加一个 annotation,从而触发对该 ` PDGroup ` 下所有 PD Pod 的优雅滚动重启:
19+
20+ ``` yaml
21+ apiVersion : core.pingcap.com/v1alpha1
22+ kind : PDGroup
23+ metadata :
24+ name : pd
25+ spec :
26+ replicas : 3
27+ template :
28+ metadata :
29+ annotations :
30+ pingcap.com/restartedAt : 2025-06-30T12:00
31+ ` ` `
32+
33+ ## 优雅重启某个组件的单个 Pod
34+
35+ 你可以单独重启 TiDB 集群中的特定 Pod。不同组件的 Pod,操作略有不同。
36+
37+ 对于 TiKV Pod,为确保有足够时间驱逐 Region leader,在删除 Pod 时需要指定 ` --grace-period` 选项,否则操作可能失败。以下示例为 TiKV Pod 设置了 60 秒的宽限期:
38+
39+ ` ` ` shell
40+ kubectl -n ${namespace} delete pod ${pod_name} --grace-period=60
41+ ` ` `
42+
43+ 其他组件的 Pod 可以直接删除,TiDB Operator 会自动优雅重启这些 Pod:
44+
45+ ` ` ` shell
46+ kubectl -n ${namespace} delete pod ${pod_name}
47+ ` ` `
You can’t perform that action at this time.
0 commit comments