|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: 'kubeadm:使用 etcd Learner 安全地接入控制平面节点' |
| 4 | +date: 2023-09-25 |
| 5 | +slug: kubeadm-use-etcd-learner-mode |
| 6 | +--- |
| 7 | +<!-- |
| 8 | +layout: blog |
| 9 | +title: 'kubeadm: Use etcd Learner to Join a Control Plane Node Safely' |
| 10 | +date: 2023-09-25 |
| 11 | +slug: kubeadm-use-etcd-learner-mode |
| 12 | +--> |
| 13 | + |
| 14 | +<!-- |
| 15 | +**Author:** Paco Xu (DaoCloud) |
| 16 | +--> |
| 17 | +**作者:** Paco Xu (DaoCloud) |
| 18 | + |
| 19 | +**译者:** [Michael Yao](https://github.com/windsonsea) (DaoCloud) |
| 20 | + |
| 21 | +<!-- |
| 22 | +The [`kubeadm`](/docs/reference/setup-tools/kubeadm/) tool now supports etcd learner mode, which |
| 23 | +allows you to enhance the resilience and stability |
| 24 | +of your Kubernetes clusters by leveraging the [learner mode](https://etcd.io/docs/v3.4/learning/design-learner/#appendix-learner-implementation-in-v34) |
| 25 | +feature introduced in etcd version 3.4. |
| 26 | +This guide will walk you through using etcd learner mode with kubeadm. By default, kubeadm runs |
| 27 | +a local etcd instance on each control plane node. |
| 28 | +--> |
| 29 | +[`kubeadm`](/zh-cn/docs/reference/setup-tools/kubeadm/) 工具现在支持 etcd learner 模式, |
| 30 | +借助 etcd 3.4 版本引入的 |
| 31 | +[learner 模式](https://etcd.io/docs/v3.4/learning/design-learner/#appendix-learner-implementation-in-v34)特性, |
| 32 | +可以提高 Kubernetes 集群的弹性和稳定性。本文将介绍如何在 kubeadm 中使用 etcd learner 模式。 |
| 33 | +默认情况下,kubeadm 在每个控制平面节点上运行一个本地 etcd 实例。 |
| 34 | + |
| 35 | +<!-- |
| 36 | +In v1.27, kubeadm introduced a new feature gate `EtcdLearnerMode`. With this feature gate enabled, |
| 37 | +when joining a new control plane node, a new etcd member will be created as a learner and |
| 38 | +promoted to a voting member only after the etcd data are fully aligned. |
| 39 | +--> |
| 40 | +在 v1.27 中,kubeadm 引入了一个新的特性门控 `EtcdLearnerMode`。 |
| 41 | +启用此特性门控后,在加入新的控制平面节点时,一个新的 etcd 成员将被创建为 learner, |
| 42 | +只有在 etcd 数据被完全对齐后此成员才会晋升为投票成员。 |
| 43 | + |
| 44 | +<!-- |
| 45 | +## What are the advantages of using learner mode? |
| 46 | +
|
| 47 | +etcd learner mode offers several compelling reasons to consider its adoption |
| 48 | +in Kubernetes clusters: |
| 49 | +--> |
| 50 | +## 使用 etcd learner 模式的优势是什么? {#what-are-advantages-of-using-learner-mode} |
| 51 | + |
| 52 | +在 Kubernetes 集群中采用 etcd learner 模式具有以下几个优点: |
| 53 | + |
| 54 | +<!-- |
| 55 | + 1. **Enhanced Resilience**: etcd learner nodes are non-voting members that catch up with |
| 56 | + the leader's logs before becoming fully operational. This prevents new cluster members |
| 57 | + from disrupting the quorum or causing leader elections, making the cluster more resilient |
| 58 | + during membership changes. |
| 59 | + 2. **Reduced Cluster Unavailability**: Traditional approaches to adding new members often |
| 60 | + result in cluster unavailability periods, especially in slow infrastructure or misconfigurations. |
| 61 | + etcd learner mode minimizes such disruptions. |
| 62 | + 3. **Simplified Maintenance**: Learner nodes provide a safer and reversible way to add or replace |
| 63 | + cluster members. This reduces the risk of accidental cluster outages due to misconfigurations or |
| 64 | + missteps during member additions. |
| 65 | + 4. **Improved Network Tolerance**: In scenarios involving network partitions, learner mode allows |
| 66 | + for more graceful handling. Depending on the partition a new member lands, it can seamlessly |
| 67 | + integrate with the existing cluster without causing disruptions. |
| 68 | +--> |
| 69 | +1. **增强了弹性**:etcd learner 节点是非投票成员,在完全进入角色之前会追随领导者的日志。 |
| 70 | + 这样可以防止新的集群成员干扰投票结果或引起领导者选举,从而使集群在成员变更期间更具弹性。 |
| 71 | +2. **减少了集群不可用时间**:传统的添加新成员的方法通常会造成一段时间集群不可用,特别是在基础设施迟缓或误配的情况下更为明显。 |
| 72 | + 而 etcd learner 模式可以最大程度地减少此类干扰。 |
| 73 | +3. **简化了维护**:learner 节点提供了一种更安全、可逆的方式来添加或替换集群成员。 |
| 74 | + 这降低了由于误配或在成员添加过程中出错而导致集群意外失效的风险。 |
| 75 | +4. **改进了网络容错性**:在涉及网络分区的场景中,learner 模式允许更优雅的处理。 |
| 76 | + 根据新成员所落入的分区,它可以无缝地与现有集群集成,而不会造成中断。 |
| 77 | + |
| 78 | +<!-- |
| 79 | +In summary, the etcd learner mode improves the reliability and manageability of Kubernetes clusters |
| 80 | +during member additions and changes, making it a valuable feature for cluster operators. |
| 81 | +--> |
| 82 | +总之,etcd learner 模式可以在成员添加和变更期间提高 Kubernetes 集群的可靠性和可管理性, |
| 83 | +这个特性对集群运营人员很有价值。 |
| 84 | + |
| 85 | +<!-- |
| 86 | +## How nodes join a cluster that's using the new mode |
| 87 | +
|
| 88 | +### Create a Kubernetes cluster backed by etcd in learner mode {#create-K8s-cluster-etcd-learner-mode} |
| 89 | +--> |
| 90 | +## 节点如何接入使用这种新模式的集群 {#how-nodes-join-cluster-that-using-new-node} |
| 91 | + |
| 92 | +### 创建以 etcd learner 模式支撑的 Kubernetes 集群 {#create-K8s-cluster-etcd-learner-mode} |
| 93 | + |
| 94 | +<!-- |
| 95 | +For a general explanation about creating highly available clusters with kubeadm, you can refer to |
| 96 | +[Creating Highly Available Clusters with kubeadm](/docs/setup/production-environment/tools/kubeadm/high-availability/). |
| 97 | +
|
| 98 | +To create a Kubernetes cluster, backed by etcd in learner mode, using kubeadm, follow these steps: |
| 99 | +--> |
| 100 | +关于使用 kubeadm 创建高可用集群的通用说明, |
| 101 | +请参阅[使用 kubeadm 创建高可用集群](/zh-cn/docs/setup/production-environment/tools/kubeadm/high-availability/)。 |
| 102 | + |
| 103 | +要使用 kubeadm 创建一个后台是 learner 模式的 etcd 的 Kubernetes 集群,按照以下步骤操作: |
| 104 | + |
| 105 | +```shell |
| 106 | +# kubeadm init --feature-gates=EtcdLearnerMode=true ... |
| 107 | +kubeadm init --config=kubeadm-config.yaml |
| 108 | +``` |
| 109 | + |
| 110 | +<!-- |
| 111 | +The kubeadm configuration file is like below: |
| 112 | +--> |
| 113 | +kubeadm 配置文件如下: |
| 114 | + |
| 115 | +```yaml |
| 116 | +apiVersion: kubeadm.k8s.io/v1beta3 |
| 117 | +kind: ClusterConfiguration |
| 118 | +featureGates: |
| 119 | + EtcdLearnerMode: true |
| 120 | +``` |
| 121 | +
|
| 122 | +<!-- |
| 123 | +The kubeadm tool deploys a single-node Kubernetes cluster with etcd set to use learner mode. |
| 124 | +--> |
| 125 | +这里,kubeadm 工具部署单节点 Kubernetes 集群,其中的 etcd 被设置为 learner 模式。 |
| 126 | +
|
| 127 | +<!-- |
| 128 | +### Join nodes to the Kubernetes cluster |
| 129 | +
|
| 130 | +Before joining a control-plane node to the new Kubernetes cluster, ensure that the existing control plane nodes |
| 131 | +and all etcd members are healthy. |
| 132 | +
|
| 133 | +Check the cluster health with `etcdctl`. If `etcdctl` isn't available, you can run this tool inside a container image. |
| 134 | +You would do that directly with your container runtime using a tool such as `crictl run` and not through Kubernetes |
| 135 | + |
| 136 | +Here is an example on a client command that uses secure communication to check the cluster health of the etcd cluster: |
| 137 | +--> |
| 138 | +### 将节点接入 Kubernetes 集群 {#join-nodes-to-the-kubernetes-cluster} |
| 139 | + |
| 140 | +在将控制平面节点接入新的 Kubernetes 集群之前,确保现有的控制平面节点和所有 etcd 成员都健康。 |
| 141 | + |
| 142 | +使用 `etcdctl` 检查集群的健康状况。如果 `etcdctl` 不可用,你可以运行在容器镜像内的这个工具。 |
| 143 | +你可以直接使用 `crictl run` 这类容器运行时工具而不是通过 Kubernetes 来执行此操作。 |
| 144 | + |
| 145 | +以下是一个使用安全通信来检查 etcd 集群健康状况的客户端命令示例: |
| 146 | + |
| 147 | +```shell |
| 148 | +ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 \ |
| 149 | + --cert=/etc/kubernetes/pki/etcd/server.crt \ |
| 150 | + --key=/etc/kubernetes/pki/etcd/server.key \ |
| 151 | + --cacert=/etc/kubernetes/pki/etcd/ca.crt \ |
| 152 | + member list |
| 153 | +... |
| 154 | +dc543c4d307fadb9, started, node1, https://10.6.177.40:2380, https://10.6.177.40:2379, false |
| 155 | +``` |
| 156 | + |
| 157 | +<!-- |
| 158 | +To check if the Kubernetes control plane is healthy, run `kubectl get node -l node-role.kubernetes.io/control-plane=` |
| 159 | +and check if the nodes are ready. |
| 160 | + |
| 161 | +Note: It is recommended to have an odd number of members in a etcd cluster. |
| 162 | + |
| 163 | +Before joining a worker node to the new Kubernetes cluster, ensure that the control plane nodes are healthy. |
| 164 | +--> |
| 165 | +要检查 Kubernetes 控制平面是否健康,运行 `kubectl get node -l node-role.kubernetes.io/control-plane=` |
| 166 | +并检查节点是否就绪。 |
| 167 | + |
| 168 | +注意:建议在 etcd 集群中的成员个数为奇数。 |
| 169 | + |
| 170 | +在将工作节点接入新的 Kubernetes 集群之前,确保控制平面节点健康。 |
| 171 | + |
| 172 | +<!-- |
| 173 | +## What's next |
| 174 | + |
| 175 | +- The feature gate `EtcdLearnerMode` is alpha in v1.27 and we expect it to graduate to beta in the next |
| 176 | + minor release of Kubernetes (v1.29). |
| 177 | +- etcd has an open issue that may make the process more automatic: |
| 178 | + [Support auto-promoting a learner member to a voting member](https://github.com/etcd-io/etcd/issues/15107). |
| 179 | +- Learn more about the kubeadm [configuration format](/docs/reference/config-api/kubeadm-config.v1beta3/) here. |
| 180 | +--> |
| 181 | +## 接下来的步骤 {#whats-next} |
| 182 | + |
| 183 | +- 特性门控 `EtcdLearnerMode` 在 v1.27 中为 Alpha,预计会在 Kubernetes 的下一个小版本发布(v1.29)中进阶至 Beta。 |
| 184 | +- etcd 社区有一个开放问题,目的是使这个过程更加自动化: |
| 185 | + [支持自动将 learner 成员晋升为投票成员](https://github.com/etcd-io/etcd/issues/15107)。 |
| 186 | +- 更多细节参阅 kubeadm [配置格式](/zh-cn/docs/reference/config-api/kubeadm-config.v1beta3/)。 |
| 187 | + |
| 188 | +<!-- |
| 189 | +## Feedback |
| 190 | + |
| 191 | +Was this guide helpful? If you have any feedback or encounter any issues, please let us know. |
| 192 | +Your feedback is always welcome! Join the bi-weekly [SIG Cluster Lifecycle meeting](https://docs.google.com/document/d/1Gmc7LyCIL_148a9Tft7pdhdee0NBHdOfHS1SAF0duI4/edit) |
| 193 | +or weekly [kubeadm office hours](https://docs.google.com/document/d/130_kiXjG7graFNSnIAgtMS1G8zPDwpkshgfRYS0nggo/edit). Or reach us via [Slack](https://slack.k8s.io/) (channel **#kubeadm**), or the [SIG's mailing list](https://groups.google.com/g/kubernetes-sig-cluster-lifecycle). |
| 194 | +--> |
| 195 | +## 反馈 {#feedback} |
| 196 | + |
| 197 | +本文对你有帮助吗?如果你有任何反馈或遇到任何问题,请告诉我们。 |
| 198 | +非常欢迎你提出反馈!你可以参加 [SIG Cluster Lifecycle 双周例会](https://docs.google.com/document/d/1Gmc7LyCIL_148a9Tft7pdhdee0NBHdOfHS1SAF0duI4/edit) |
| 199 | +或 [kubeadm 每周讨论会](https://docs.google.com/document/d/130_kiXjG7graFNSnIAgtMS1G8zPDwpkshgfRYS0nggo/edit)。 |
| 200 | +你还可以通过 [Slack](https://slack.k8s.io/)(频道 **#kubeadm**)或 |
| 201 | +[SIG 邮件列表](https://groups.google.com/g/kubernetes-sig-cluster-lifecycle)联系我们。 |
0 commit comments