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

Merged
merged 9 commits into from
Nov 7, 2024
Merged
Changes from 6 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
96 changes: 96 additions & 0 deletions zh/enable-tls-between-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ aliases: ['/docs-cn/tidb-in-kubernetes/dev/enable-tls-between-components/']
> **注意:**
>
> 在集群创建后,不能修改此字段,否则将导致集群升级失败,此时需要删除已有集群,并重新创建。
>
> 在无法重建的情况下,如果希望集群创建后再开启 TLS,可尝试[以下方式](#从非-tls-集群升级到-tls-集群)(**请谨慎操作**):

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

Expand Down Expand Up @@ -1656,3 +1658,97 @@ 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。
>

1. 如果存在多个 PD 节点,缩容 PD 至 1 个节点。

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

3. 参考 [第二步:部署 TiDB 集群](#第二步部署-tidb-集群) ,可使用以下命令来更新 TiDB 集群,等待 PD pod 完成重启后继续下一步操作。

{{< copyable "shell-regular" >}}

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

输出示例:

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

也可以参考 [第二步:部署 TiDB 集群](#第二步部署-tidb-集群),选择设置 `cert-allowed-cn` 配置项(TiDB 为 `cluster-verify-cn`),用来验证集群间各组件证书的 CN (Common Name)。

4. 使用 `kubectl exec` 进入 PD pod,下载 etcdctl。参考 [etcdctl 安装指南](https://etcd.io/docs/v3.4/install/),etcdctl 位于解压后的文件夹目录下。

5. 查看 etcd member,可见 peerURLs 此时为 `http`:

{{< copyable "shell-regular" >}}

``` 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, http://basic-pd-0.basic-pd-peer.pingcap.svc:2380, https://basic-pd-0.basic-pd-peer.pingcap.svc:2379, false
```

**示例解释:**

memberID 和 peerURLs 需要在下个步骤更新 etcd member 时填入:

1. 包含 memberID,示例中为 `e94cfb12fa384e23`。

2. 包含 peerURLs,示例中为 `http://basic-pd-0.basic-pd-peer.pingcap.svc:2380`。

6. 修改 etcd member 的 peerURLs 为 `https`:

**注意:**

peerURLS 需要修改 `http` 为 `https`。

{{< copyable "shell-regular" >}}

``` 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
```

7. 查看此时 etcd member 的 peerURLs,确认已经修改为 `https`:

{{< copyable "shell-regular" >}}

``` 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
```

此时 peerURLs 已更新为 `https://basic-pd-0.basic-pd-peer.pingcap.svc:2380`。

8. 若缩容过 PD 节点,需扩容 PD 至原有数量。
9. 等待其他 pod 重启更新。