Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pd/tls: add upgrade tls description #2612

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion zh/enable-tls-between-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ aliases: ['/docs-cn/tidb-in-kubernetes/dev/enable-tls-between-components/']

> **注意:**
>
> 在集群创建后,不能修改此字段,否则将导致集群升级失败,此时需要删除已有集群,并重新创建。
> - 在集群创建后,不能修改此字段,否则将导致集群升级失败,此时需要删除已有集群,并重新创建。
> - 若集群无法重建且需要启用 TLS,请参阅[从非 TLS 集群升级到 TLS 集群](#从非-tls-集群升级到-tls-集群)。

3. 配置 `pd-ctl`,`tikv-ctl` 连接集群。

Expand Down Expand Up @@ -1656,3 +1657,88 @@ aliases: ['/docs-cn/tidb-in-kubernetes/dev/enable-tls-between-components/']
cd /var/lib/cluster-client-tls
/tikv-ctl --ca-path=ca.crt --cert-path=tls.crt --key-path=tls.key --host 127.0.0.1:20160 cluster
```

## 将非 TLS 集群升级为 TLS 集群

csuzhangxc marked this conversation as resolved.
Show resolved Hide resolved
本节介绍如何为现有的非 TLS TiDB 集群启用 TLS 加密通信。

> **注意:**
>
> 该操作仅适用于无法重建的现有集群。在开始操作前,请确保已充分理解每个步骤及其潜在风险。

1. 如果集群包含多个 PD 节点,需要先将 PD 节点数量缩减为 1 个。

2. 参考[第一步:为 TiDB 集群各个组件生成证书](#第一步为-tidb-集群各个组件生成证书)生成 TLS 证书,并创建 Kubernetes Secret 对象。

3. 启用 TLS:

你可以选择以下两种方法之一启用 TLS:

- 方法 1:执行以下命令更新 TiDB 集群配置,等待 PD Pod 完成重启后继续下一步。

``` shell
kubectl patch tc ${cluster_name} -n ${namespace} --type merge -p '{
"spec": {
"tlsCluster": {
"enabled": true
}
}
}'
```

输出示例:

``` shell
tidbcluster.pingcap.com/basic patched
```

- 方法 2:参考[第二步:部署 TiDB 集群](#第二步部署-tidb-集群)启用 TLS,同时设置 `cert-allowed-cn` 配置项(TiDB 为 `cluster-verify-cn`),用于验证集群间各组件证书的 CN (Common Name)。

4. 配置 PD 节点:

1. 使用 `kubectl exec` 进入 PD Pod 并安装 etcdctl。详细安装步骤可参考 [etcdctl 安装指南](https://etcd.io/docs/v3.4/install/)。安装完成后,etcdctl 位于解压后的文件夹目录下。

2. 查看 etcd 成员信息,此时 `peerURLs` 使用 HTTP 协议:

``` shell
./etcdctl --endpoints https://127.0.0.1:2379 --cert /var/lib/pd-tls/tls.crt --key /var/lib/pd-tls/tls.key --cacert /var/lib/pd-tls/ca.crt member list
```

输出示例:

``` shell
# memberID status name peerURLs clientURL isLearner
e94cfb12fa384e23, started, basic-pd-0, http://basic-pd-0.basic-pd-peer.pingcap.svc:2380, https://basic-pd-0.basic-pd-peer.pingcap.svc:2379, false
```

记录以下信息用于下一步操作:

- `memberID`:示例中为 `e94cfb12fa384e23`。
- `peerURLs`:示例中为 `http://basic-pd-0.basic-pd-peer.pingcap.svc:2380`。

3. 将 etcd member 的 `peerURLs` 从 HTTP 更新为 HTTPS 协议:

``` shell
./etcdctl --endpoints https://127.0.0.1:2379 --cert /var/lib/pd-tls/tls.crt --key /var/lib/pd-tls/tls.key --cacert /var/lib/pd-tls/ca.crt member update e94cfb12fa384e23 --peer-urls="https://basic-pd-0.basic-pd-peer.pingcap.svc:2380"
```

输出示例:

``` shell
Member e94cfb12fa384e23 updated in cluster 32ab5936d81ad54c
```

4. 查看更新后的 `peerURLs`,确保已更新为 HTTPS 协议:

``` shell
./etcdctl --endpoints https://127.0.0.1:2379 --cert /var/lib/pd-tls/tls.crt --key /var/lib/pd-tls/tls.key --cacert /var/lib/pd-tls/ca.crt member list
```

输出示例:

``` shell
e94cfb12fa384e23, started, basic-pd-0, https://basic-pd-0.basic-pd-peer.pingcap.svc:2380, https://basic-pd-0.basic-pd-peer.pingcap.svc:2379, false
```

5. 如果之前进行了 PD 节点缩容,请将其扩容为原有数量。
6. 等待 TiDB 集群中的所有 Pod 完成重启。
Loading