@@ -3,7 +3,6 @@ title: 使用 kubeadm 创建一个高可用 etcd 集群
3
3
content_type : task
4
4
weight : 70
5
5
---
6
-
7
6
<!--
8
7
reviewers:
9
8
- sig-cluster-lifecycle
@@ -32,15 +31,13 @@ It is also possible to treat the etcd cluster as external and provision
32
31
etcd instances on separate hosts. The differences between the two approaches are covered in the
33
32
[Options for Highly Available topology](/docs/setup/production-environment/tools/kubeadm/ha-topology) page.
34
33
-->
35
-
36
34
默认情况下,kubeadm 在每个控制平面节点上运行一个本地 etcd 实例。也可以使用外部的 etcd 集群,并在不同的主机上提供 etcd 实例。
37
- 这两种方法的区别在 [ 高可用拓扑的选项] ( /zh-cn/docs/setup/production-environment/tools/kubeadm/ha-topology ) 页面中阐述。
35
+ 这两种方法的区别在[ 高可用拓扑的选项] ( /zh-cn/docs/setup/production-environment/tools/kubeadm/ha-topology ) 页面中阐述。
38
36
39
37
<!--
40
38
This task walks through the process of creating a high availability external
41
39
etcd cluster of three members that can be used by kubeadm during cluster creation.
42
40
-->
43
-
44
41
这个任务将指导你创建一个由三个成员组成的高可用外部 etcd 集群,该集群在创建过程中可被 kubeadm 使用。
45
42
46
43
## {{% heading "prerequisites" %}}
@@ -50,7 +47,8 @@ etcd cluster of three members that can be used by kubeadm during cluster creatio
50
47
document assumes these default ports. However, they are configurable through
51
48
the kubeadm config file.
52
49
-->
53
- - 三个可以通过 2379 和 2380 端口相互通信的主机。本文档使用这些作为默认端口。不过,它们可以通过 kubeadm 的配置文件进行自定义。
50
+ - 三个可以通过 2379 和 2380 端口相互通信的主机。本文档使用这些作为默认端口。
51
+ 不过,它们可以通过 kubeadm 的配置文件进行自定义。
54
52
<!--
55
53
- Each host must have systemd and a bash compatible shell installed.
56
54
- Each host must [have a container runtime, kubelet, and kubeadm installed](/docs/setup/production-environment/tools/kubeadm/install-kubeadm/).
@@ -63,20 +61,20 @@ etcd cluster of three members that can be used by kubeadm during cluster creatio
63
61
[static pods](/docs/tasks/configure-pod-container/static-pod/) managed by a kubelet.
64
62
-->
65
63
- 每个主机都应该能够访问 Kubernetes 容器镜像仓库 (registry.k8s.io),
66
- 或者使用 ` kubeadm config images list/pull ` 列出/拉取所需的 etcd 镜像。
67
- 本指南将把 etcd 实例设置为由 kubelet 管理的[ 静态 Pod] ( /zh-cn/docs/tasks/configure-pod-container/static-pod/ ) 。
64
+ 或者使用 ` kubeadm config images list/pull ` 列出/拉取所需的 etcd 镜像。
65
+ 本指南将把 etcd 实例设置为由 kubelet 管理的[ 静态 Pod] ( /zh-cn/docs/tasks/configure-pod-container/static-pod/ ) 。
68
66
<!--
69
67
- Some infrastructure to copy files between hosts. For example `ssh` and `scp`
70
68
can satisfy this requirement.
71
69
-->
72
- - 一些可以用来在主机间复制文件的基础设施。例如 ` ssh ` 和 ` scp ` 就可以满足需求 。
70
+ - 一些可以用来在主机间复制文件的基础设施。例如 ` ssh ` 和 ` scp ` 就可以满足此需求 。
73
71
74
72
<!-- steps -->
75
73
76
74
<!--
77
75
## Setting up the cluster
78
76
-->
79
- ## 建立集群
77
+ ## 建立集群 {#setting-up-cluster}
80
78
81
79
<!--
82
80
The general approach is to generate all certs on one node and only distribute
@@ -99,25 +97,37 @@ The examples below use IPv4 addresses but you can also configure kubeadm, the ku
99
97
to use IPv6 addresses. Dual-stack is supported by some Kubernetes options, but not by etcd. For more details
100
98
on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/setup/production-environment/tools/kubeadm/dual-stack-support/).
101
99
-->
102
- 下面的例子使用 IPv4 地址,但是你也可以使用 IPv6 地址配置 kubeadm、kubelet 和 etcd。一些 Kubernetes 选项支持双协议栈,但是 etcd 不支持。
103
- 关于 Kubernetes 双协议栈支持的更多细节,请参见 [ kubeadm 的双栈支持] ( /zh-cn/docs/setup/production-environment/tools/kubeadm/dual-stack-support/ ) 。
100
+ 下面的例子使用 IPv4 地址,但是你也可以使用 IPv6 地址配置 kubeadm、kubelet 和 etcd。
101
+ 一些 Kubernetes 选项支持双协议栈,但是 etcd 不支持。关于 Kubernetes 双协议栈支持的更多细节,
102
+ 请参见 [ kubeadm 的双栈支持] ( /zh-cn/docs/setup/production-environment/tools/kubeadm/dual-stack-support/ ) 。
104
103
{{< /note >}}
105
104
106
105
<!--
107
106
1. Configure the kubelet to be a service manager for etcd.
108
-
109
- {{< note >}}You must do this on every host where etcd should be running.{{< /note >}}
110
- Since etcd was created first, you must override the service priority by creating a new unit file
111
- that has higher precedence than the kubeadm-provided kubelet unit file.
112
107
-->
113
108
1 . 将 kubelet 配置为 etcd 的服务管理器。
114
109
115
110
{{< note >}}
111
+ <!--
112
+ You must do this on every host where etcd should be running.
113
+ -->
116
114
你必须在要运行 etcd 的所有主机上执行此操作。
117
115
{{< /note >}}
116
+
117
+ <!--
118
+ Since etcd was created first, you must override the service priority by creating a new unit file
119
+ that has higher precedence than the kubeadm-provided kubelet unit file.
120
+ -->
118
121
由于 etcd 是首先创建的,因此你必须通过创建具有更高优先级的新文件来覆盖
119
122
kubeadm 提供的 kubelet 单元文件。
120
123
124
+ <!--
125
+ ```sh
126
+ cat << EOF > /etc/systemd/system/kubelet.service.d/kubelet.conf
127
+ # Replace "systemd" with the cgroup driver of your container runtime. The default value in the kubelet is "cgroupfs".
128
+ # Replace the value of "containerRuntimeEndpoint" for a different container runtime if needed.
129
+ ```
130
+ -->
121
131
``` sh
122
132
cat << EOF > /etc/systemd/system/kubelet.service.d/kubelet.conf
123
133
# 将下面的 "systemd" 替换为你的容器运行时所使用的 cgroup 驱动。
@@ -126,12 +136,19 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
126
136
#
127
137
apiVersion: kubelet.config.k8s.io/v1beta1
128
138
kind: KubeletConfiguration
139
+ authentication:
140
+ anonymous:
141
+ enabled: false
142
+ webhook:
143
+ enabled: false
144
+ authorization:
145
+ mode: AlwaysAllow
129
146
cgroupDriver: systemd
130
147
address: 127.0.0.1
131
148
containerRuntimeEndpoint: unix:///var/run/containerd/containerd.sock
132
149
staticPodPath: /etc/kubernetes/manifests
133
150
EOF
134
-
151
+
135
152
cat << EOF > /etc/systemd/system/kubelet.service.d/20-etcd-service-manager.conf
136
153
[Service]
137
154
ExecStart=
@@ -162,8 +179,23 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
162
179
163
180
使用以下脚本为每个将要运行 etcd 成员的主机生成一个 kubeadm 配置文件。
164
181
182
+ < ! --
165
183
` ` ` sh
166
- # 使用你的主机 IP 替换 HOST0、HOST1 和 HOST2 的 IP 地址
184
+ # Update HOST0, HOST1 and HOST2 with the IPs of your hosts
185
+ export HOST0=10.0.0.6
186
+ export HOST1=10.0.0.7
187
+ export HOST2=10.0.0.8
188
+
189
+ # Update NAME0, NAME1 and NAME2 with the hostnames of your hosts
190
+ export NAME0="infra0"
191
+ export NAME1="infra1"
192
+ export NAME2="infra2"
193
+
194
+ # Create temp directories to store files that will end up on other hosts
195
+ mkdir -p /tmp/${HOST0} / /tmp/${HOST1} / /tmp/${HOST2} /
196
+ -->
197
+ ` ` ` sh
198
+ # 使用你的主机 IP 更新 HOST0、HOST1 和 HOST2 的 IP 地址
167
199
export HOST0=10.0.0.6
168
200
export HOST1=10.0.0.7
169
201
export HOST2=10.0.0.8
@@ -219,7 +251,7 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
219
251
`/etc/kubernetes/pki/etcd/ca.key`. After those files have been copied,
220
252
proceed to the next step, "Create certificates for each member".
221
253
-->
222
- 3. 生成证书颁发机构
254
+ 3. 生成证书颁发机构。
223
255
224
256
如果你已经拥有 CA,那么唯一的操作是复制 CA 的 `crt` 和 `key` 文件到
225
257
`etc/kubernetes/pki/etcd/ca.crt` 和 `/etc/kubernetes/pki/etcd/ca.key`。
@@ -245,8 +277,15 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
245
277
<!--
246
278
1. Create certificates for each member.
247
279
-->
248
- 4. 为每个成员创建证书
280
+ 4. 为每个成员创建证书。
249
281
282
+ <!--
283
+ ```sh
284
+ # cleanup non-reusable certificates
285
+ # No need to move the certs because they are for HOST0
286
+ # clean up certs that should not be copied off this host
287
+ ```
288
+ -->
250
289
```shell
251
290
kubeadm init phase certs etcd-server --config=/tmp/${HOST2}/kubeadmcfg.yaml
252
291
kubeadm init phase certs etcd-peer --config=/tmp/${HOST2}/kubeadmcfg.yaml
@@ -279,7 +318,7 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
279
318
The certificates have been generated and now they must be moved to their
280
319
respective hosts.
281
320
-->
282
- 5. 复制证书和 kubeadm 配置
321
+ 5. 复制证书和 kubeadm 配置。
283
322
284
323
证书已生成,现在必须将它们移动到对应的主机。
285
324
@@ -371,7 +410,7 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
371
410
manifests. On each host run the ` kubeadm` command to generate a static manifest
372
411
for etcd.
373
412
-->
374
- 7. 创建静态 Pod 清单
413
+ 7. 创建静态 Pod 清单。
375
414
376
415
既然证书和配置已经就绪,是时候去创建清单了。
377
416
在每台主机上运行 ` kubeadm` 命令来生成 etcd 使用的静态清单。
@@ -385,7 +424,7 @@ on Kubernetes dual-stack support see [Dual-stack support with kubeadm](/docs/set
385
424
< ! --
386
425
1. Optional: Check the cluster health.
387
426
-->
388
- 8. 可选:检查集群运行状况
427
+ 8. 可选:检查集群运行状况。
389
428
390
429
< ! --
391
430
If ` etcdctl` isn' t available, you can run this tool inside a container image.
0 commit comments