Skip to content

Commit c782e59

Browse files
authored
Merge pull request #39994 from windsonsea/runsta
[zh] sync run-replicated-stateful-application.md
2 parents d5371bc + d96eb8e commit c782e59

File tree

1 file changed

+67
-69
lines changed

1 file changed

+67
-69
lines changed

content/zh-cn/docs/tasks/run-application/run-replicated-stateful-application.md

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -30,53 +30,52 @@ replication.
3030
示例应用的拓扑结构有一个主服务器和多个副本,使用异步的基于行(Row-Based)
3131
的数据复制。
3232

33+
{{< note >}}
3334
<!--
3435
**This is not a production configuration**. MySQL settings remain on insecure defaults to keep the focus
3536
on general patterns for running stateful applications in Kubernetes.
3637
-->
37-
{{< note >}}
3838
**这一配置不适合生产环境。**
3939
MySQL 设置都使用的是不安全的默认值,这是因为我们想把重点放在 Kubernetes
4040
中运行有状态应用程序的一般模式上。
4141
{{< /note >}}
4242

4343
## {{% heading "prerequisites" %}}
4444

45-
* {{< include "task-tutorial-prereqs.md" >}}
46-
* {{< include "default-storage-class-prereqs.md" >}}
47-
45+
- {{< include "task-tutorial-prereqs.md" >}}
46+
- {{< include "default-storage-class-prereqs.md" >}}
4847
<!--
49-
* This tutorial assumes you are familiar with
48+
- This tutorial assumes you are familiar with
5049
[PersistentVolumes](/docs/concepts/storage/persistent-volumes/)
5150
and [StatefulSets](/docs/concepts/workloads/controllers/statefulset/),
5251
as well as other core concepts like [Pods](/docs/concepts/workloads/pods/),
5352
[Services](/docs/concepts/services-networking/service/), and
5453
[ConfigMaps](/docs/tasks/configure-pod-container/configure-pod-configmap/).
55-
* Some familiarity with MySQL helps, but this tutorial aims to present
54+
- Some familiarity with MySQL helps, but this tutorial aims to present
5655
general patterns that should be useful for other systems.
57-
* You are using the default namespace or another namespace that does not contain any conflicting objects.
56+
- You are using the default namespace or another namespace that does not contain any conflicting objects.
5857
-->
59-
* 本教程假定你熟悉
58+
- 本教程假定你熟悉
6059
[PersistentVolumes](/zh-cn/docs/concepts/storage/persistent-volumes/)
61-
[StatefulSet](/zh-cn/docs/concepts/workloads/controllers/statefulset/),
60+
[StatefulSet](/zh-cn/docs/concepts/workloads/controllers/statefulset/)
6261
以及其他核心概念,例如 [Pod](/zh-cn/docs/concepts/workloads/pods/)
63-
[服务](/zh-cn/docs/concepts/services-networking/service/)
64-
[ConfigMap](/zh-cn/docs/tasks/configure-pod-container/configure-pod-configmap/).
65-
* 熟悉 MySQL 会有所帮助,但是本教程旨在介绍对其他系统应该有用的常规模式。
66-
* 你正在使用默认命名空间或不包含任何冲突对象的另一个命名空间。
62+
[服务](/zh-cn/docs/concepts/services-networking/service/)
63+
[ConfigMap](/zh-cn/docs/tasks/configure-pod-container/configure-pod-configmap/)
64+
- 熟悉 MySQL 会有所帮助,但是本教程旨在介绍对其他系统应该有用的常规模式。
65+
- 你正在使用默认命名空间或不包含任何冲突对象的另一个命名空间。
6766

6867
## {{% heading "objectives" %}}
6968

7069
<!--
71-
* Deploy a replicated MySQL topology with a StatefulSet.
72-
* Send MySQL client traffic.
73-
* Observe resistance to downtime.
74-
* Scale the StatefulSet up and down.
70+
- Deploy a replicated MySQL topology with a StatefulSet.
71+
- Send MySQL client traffic.
72+
- Observe resistance to downtime.
73+
- Scale the StatefulSet up and down.
7574
-->
76-
* 使用 StatefulSet 部署多副本 MySQL 拓扑架构。
77-
* 发送 MySQL 客户端请求
78-
* 观察对宕机的抵抗力
79-
* 扩缩 StatefulSet 的规模
75+
- 使用 StatefulSet 部署多副本 MySQL 拓扑架构。
76+
- 发送 MySQL 客户端请求
77+
- 观察对宕机的抵抗力
78+
- 扩缩 StatefulSet 的规模
8079

8180
<!-- lessoncontent -->
8281

@@ -119,7 +118,7 @@ and you want replicas to reject any writes that don't come via replication.
119118
There's nothing special about the ConfigMap itself that causes different
120119
portions to apply to different Pods.
121120
Each Pod decides which portion to look at as it's initializing,
122-
based on information provided by the StatefulSet controller.
121+
based on information provided by the StatefulSet controller.
123122
-->
124123
ConfigMap 本身没有什么特别之处,因而也不会出现不同部分应用于不同的 Pod 的情况。
125124
每个 Pod 都会在初始化时基于 StatefulSet 控制器提供的信息决定要查看的部分。
@@ -145,7 +144,7 @@ The headless Service provides a home for the DNS entries that the StatefulSet
145144
Pod that's part of the set.
146145
Because the headless Service is named `mysql`, the Pods are accessible by
147146
resolving `<pod-name>.mysql` from within any other Pod in the same Kubernetes
148-
cluster and namespace.
147+
cluster and namespace.
149148
-->
150149
这个无头 Service 给 StatefulSet {{< glossary_tooltip text="控制器" term_id="controller" >}}
151150
为集合中每个 Pod 创建的 DNS 条目提供了一个宿主。
@@ -156,7 +155,7 @@ cluster and namespace.
156155
The client Service, called `mysql-read`, is a normal Service with its own
157156
cluster IP that distributes connections across all MySQL Pods that report
158157
being Ready. The set of potential endpoints includes the primary MySQL server and all
159-
replicas.
158+
replicas.
160159
-->
161160
客户端 Service 称为 `mysql-read`,是一种常规 Service,具有其自己的集群 IP。
162161
该集群 IP 在报告就绪的所有 MySQL Pod 之间分配连接。
@@ -166,7 +165,7 @@ replicas.
166165
Note that only read queries can use the load-balanced client Service.
167166
Because there is only one primary MySQL server, clients should connect directly to the
168167
primary MySQL Pod (through its DNS entry within the headless Service) to execute
169-
writes.
168+
writes.
170169
-->
171170
请注意,只有读查询才能使用负载平衡的客户端 Service。
172171
因为只有一个 MySQL 主服务器,所以客户端应直接连接到 MySQL 主服务器 Pod
@@ -175,7 +174,7 @@ writes.
175174
<!--
176175
### Create the StatefulSet {#statefulset}
177176
178-
Finally, create the StatefulSet from the following YAML configuration file:
177+
Finally, create the StatefulSet from the following YAML configuration file:
179178
-->
180179
### 创建 StatefulSet {#statefulset}
181180

@@ -218,8 +217,8 @@ Press **Ctrl+C** to cancel the watch.
218217
If you don't see any progress, make sure you have a dynamic PersistentVolume
219218
provisioner enabled, as mentioned in the [prerequisites](#before-you-begin).
220219
-->
221-
如果你看不到任何进度,确保已启用[前提条件](#准备开始)
222-
中提到的动态 PersistentVolume 制备程序
220+
如果你看不到任何进度,确保已启用[前提条件](#准备开始)中提到的动态
221+
PersistentVolume 制备器
223222
{{< /note >}}
224223

225224
<!--
@@ -237,7 +236,7 @@ The StatefulSet controller starts Pods one at a time, in order by their
237236
ordinal index.
238237
It waits until each Pod reports being Ready before starting the next one.
239238
-->
240-
## 了解有状态的 Pod 初始化
239+
## 了解有状态的 Pod 初始化 {#understanding-stateful-pod-init}
241240

242241
StatefulSet 控制器按序数索引顺序地每次启动一个 Pod。
243242
它一直等到每个 Pod 报告就绪才再启动下一个 Pod。
@@ -263,16 +262,16 @@ Before starting any of the containers in the Pod spec, the Pod first runs any
263262
[init Containers](/docs/concepts/workloads/pods/init-containers/)
264263
in the order defined.
265264
-->
266-
### 生成配置
265+
### 生成配置 {#generating-config}
267266

268267
在启动 Pod 规约中的任何容器之前,Pod 首先按顺序运行所有的
269-
[初始化容器](/zh-cn/docs/concepts/workloads/pods/init-containers/)
268+
[Init 容器](/zh-cn/docs/concepts/workloads/pods/init-containers/)
270269

271270
<!--
272271
The first init container, named `init-mysql`, generates special MySQL config
273272
files based on the ordinal index.
274273
-->
275-
第一个名为 `init-mysql` 的初始化容器根据序号索引生成特殊的 MySQL 配置文件。
274+
第一个名为 `init-mysql` 的 Init 容器根据序号索引生成特殊的 MySQL 配置文件。
276275

277276
<!--
278277
The script determines its own ordinal index by extracting it from the end of
@@ -304,9 +303,8 @@ replicating.
304303
由于示例部署结构由单个 MySQL 主节点和任意数量的副本节点组成,
305304
因此脚本仅将序数 `0` 指定为主节点,而将其他所有节点指定为副本节点。
306305

307-
与 StatefulSet 控制器的
308-
[部署顺序保证](/zh-cn/docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees)
309-
相结合,
306+
与 StatefulSet
307+
控制器的[部署顺序保证](/zh-cn/docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees)相结合,
310308
可以确保 MySQL 主服务器在创建副本服务器之前已准备就绪,以便它们可以开始复制。
311309

312310
<!--
@@ -316,7 +314,7 @@ In general, when a new Pod joins the set as a replica, it must assume the primar
316314
server might already have data on it. It also must assume that the replication
317315
logs might not go all the way back to the beginning of time.
318316
-->
319-
### 克隆现有数据
317+
### 克隆现有数据 {#cloning-existing-data}
320318

321319
通常,当新 Pod 作为副本节点加入集合时,必须假定 MySQL 主节点可能已经有数据。
322320
还必须假设复制日志可能不会一直追溯到时间的开始。
@@ -333,7 +331,7 @@ a replica Pod the first time it starts up on an empty PersistentVolume.
333331
That means it copies all existing data from another running Pod,
334332
so its local state is consistent enough to begin replicating from the primary server.
335333
-->
336-
第二个名为 `clone-mysql` 的初始化容器,第一次在带有空 PersistentVolume 的副本 Pod
334+
第二个名为 `clone-mysql` 的 Init 容器,第一次在带有空 PersistentVolume 的副本 Pod
337335
上启动时,会在从属 Pod 上执行克隆操作。
338336
这意味着它将从另一个运行中的 Pod 复制所有现有数据,使此其本地状态足够一致,
339337
从而可以开始从主服务器复制。
@@ -350,7 +348,7 @@ Ready before starting Pod `N+1`.
350348
MySQL 本身不提供执行此操作的机制,因此本示例使用了一种流行的开源工具 Percona XtraBackup。
351349
在克隆期间,源 MySQL 服务器性能可能会受到影响。
352350
为了最大程度地减少对 MySQL 主服务器的影响,该脚本指示每个 Pod 从序号较低的 Pod 中克隆。
353-
可以这样做的原因是 StatefulSet 控制器始终确保在启动 Pod `N + 1` 之前 Pod `N` 已准备就绪。
351+
可以这样做的原因是 StatefulSet 控制器始终确保在启动 Pod `N+1` 之前 Pod `N` 已准备就绪。
354352

355353
<!--
356354
### Starting replication
@@ -360,9 +358,9 @@ The MySQL Pods consist of a `mysql` container that runs the actual `mysqld`
360358
server, and an `xtrabackup` container that acts as a
361359
[sidecar](/blog/2015/06/the-distributed-system-toolkit-patterns).
362360
-->
363-
### 开始复制
361+
### 开始复制 {#starting-replication}
364362

365-
初始化容器成功完成后,应用容器将运行。MySQL Pod 由运行实际 `mysqld` 服务的 `mysql`
363+
Init 容器成功完成后,应用容器将运行。MySQL Pod 由运行实际 `mysqld` 服务的 `mysql`
366364
容器和充当[辅助工具](/blog/2015/06/the-distributed-system-toolkit-patterns)
367365
xtrabackup 容器组成。
368366

@@ -405,7 +403,7 @@ You can send test queries to the primary MySQL server (hostname `mysql-0.mysql`)
405403
by running a temporary container with the `mysql:5.7` image and running the
406404
`mysql` client binary.
407405
-->
408-
## 发送客户端请求
406+
## 发送客户端请求 {#sending-client-traffic}
409407

410408
你可以通过运行带有 `mysql:5.7` 镜像的临时容器并运行 `mysql` 客户端二进制文件,
411409
将测试查询发送到 MySQL 主服务器(主机名 `mysql-0.mysql`)。
@@ -504,9 +502,9 @@ running while you force a Pod out of the Ready state.
504502
505503
The [readiness probe](/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes)
506504
for the `mysql` container runs the command `mysql -h 127.0.0.1 -e 'SELECT 1'`
507-
to make sure the server is up and able to execute queries.
505+
to make sure the server is up and able to execute queries.
508506
-->
509-
### 破坏就绪态探测
507+
### 破坏就绪态探测 {#break-readiness-probe}
510508

511509
`mysql` 容器的[就绪态探测](/zh-cn/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes)
512510
运行命令 `mysql -h 127.0.0.1 -e 'SELECT 1'`,以确保服务器已启动并能够执行查询。
@@ -567,9 +565,9 @@ kubectl exec mysql-2 -c mysql -- mv /usr/bin/mysql.off /usr/bin/mysql
567565
### Delete Pods
568566
569567
The StatefulSet also recreates Pods if they're deleted, similar to what a
570-
ReplicaSet does for stateless Pods.
568+
ReplicaSet does for stateless Pods.
571569
-->
572-
### 删除 Pods
570+
### 删除 Pod {#delete-pods}
573571

574572
如果删除了 Pod,则 StatefulSet 还会重新创建 Pod,类似于 ReplicaSet 对无状态 Pod 所做的操作。
575573

@@ -582,7 +580,7 @@ The StatefulSet controller notices that no `mysql-2` Pod exists anymore,
582580
and creates a new one with the same name and linked to the same
583581
PersistentVolumeClaim.
584582
You should see server ID `102` disappear from the loop output for a while
585-
and then return on its own.
583+
and then return on its own.
586584
-->
587585
StatefulSet 控制器注意到不再存在 `mysql-2` Pod,于是创建一个具有相同名称并链接到相同
588586
PersistentVolumeClaim 的新 Pod。
@@ -593,7 +591,7 @@ PersistentVolumeClaim 的新 Pod。
593591
594592
If your Kubernetes cluster has multiple Nodes, you can simulate Node downtime
595593
(such as when Nodes are upgraded) by issuing a
596-
[drain](/docs/reference/generated/kubectl/kubectl-commands/#drain).
594+
[drain](/docs/reference/generated/kubectl/kubectl-commands/#drain).
597595
-->
598596
### 腾空节点 {#drain-a-node}
599597

@@ -628,15 +626,14 @@ Replace `<node-name>` with the name of the Node you found in the last step.
628626
接下来,通过运行以下命令腾空节点,该命令将其保护起来,以使新的 Pod 不能调度到该节点,
629627
然后逐出所有现有的 Pod。将 `<节点名称>` 替换为在上一步中找到的节点名称。
630628

631-
632629
{{< caution >}}
633630
<!--
634-
Draining a Node can impact other workloads and applications
631+
Draining a Node can impact other workloads and applications
635632
running on the same node. Only perform the following step in a test
636633
cluster.
637634
-->
638635
腾空一个 Node 可能影响到在该节点上运行的其他负载和应用。
639-
只应在测试集群上执行下列步骤
636+
只应在测试集群上执行下列步骤
640637
{{< /caution >}}
641638

642639
<!--
@@ -704,7 +701,7 @@ When you use MySQL replication, you can scale your read query capacity by
704701
adding replicas.
705702
For a StatefulSet, you can achieve this with a single command:
706703
-->
707-
## 扩展副本节点数量
704+
## 扩展副本节点数量 {#scaling-number-of-replicas}
708705

709706
使用 MySQL 复制时,你可以通过添加副本节点来扩展读取查询的能力。
710707
对于 StatefulSet,你可以使用单个命令实现此目的:
@@ -729,7 +726,7 @@ the `SELECT @@server_id` loop output.
729726
You can also verify that these new servers have the data you added before they
730727
existed:
731728
-->
732-
一旦 Pod 启动,你应该看到服务器 IDs `103``104` 开始出现在 `SELECT @@server_id`
729+
一旦 Pod 启动,你应该看到服务器 ID `103``104` 开始出现在 `SELECT @@server_id`
733730
循环输出中。
734731

735732
你还可以验证这些新服务器在存在之前已添加了数据:
@@ -783,7 +780,7 @@ kubectl get pvc -l app=mysql
783780
Which shows that all 5 PVCs still exist, despite having scaled the
784781
StatefulSet down to 3:
785782
-->
786-
这表明,尽管将 StatefulSet 缩小为3,所有5个 PVC 仍然存在:
783+
这表明,尽管将 StatefulSet 缩小为 3,所有 5 个 PVC 仍然存在:
787784

788785
```
789786
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
@@ -829,13 +826,15 @@ kubectl delete pvc data-mysql-4
829826
1. Verify that the Pods disappear.
830827
They might take some time to finish terminating.
831828
-->
832-
3. 验证 Pod 消失。他们可能需要一些时间才能完成终止
829+
3. 验证 Pod 消失。它们可能需要一些时间才能完成终止
833830

834831
```shell
835832
kubectl get pods -l app=mysql
836833
```
837834

838-
<!-- You'll know the Pods have terminated when the above returns: -->
835+
<!--
836+
You'll know the Pods have terminated when the above returns:
837+
-->
839838
当上述命令返回如下内容时,你就知道 Pod 已终止:
840839

841840
```
@@ -859,23 +858,22 @@ kubectl delete pvc data-mysql-4
859858
Some dynamic provisioners (such as those for EBS and PD) also release the
860859
underlying resources upon deleting the PersistentVolumes.
861860
-->
862-
5. 如果你手动供应 PersistentVolume,则还需要手动删除它们,并释放下层资源。
863-
如果你使用了动态预配器,当得知你删除 PersistentVolumeClaim 时,它将自动删除 PersistentVolume。
864-
一些动态预配器(例如用于 EBS 和 PD 的预配器)也会在删除 PersistentVolume 时释放下层资源。
861+
5. 如果你手动制备 PersistentVolume,则还需要手动删除它们,并释放下层资源。
862+
如果你使用了动态制备器,当得知你删除 PersistentVolumeClaim 时,它将自动删除 PersistentVolume。
863+
一些动态制备器(例如用于 EBS 和 PD 的制备器)也会在删除 PersistentVolume 时释放下层资源。
865864

866865
## {{% heading "whatsnext" %}}
867866

868867
<!--
869-
* Learn more about [scaling a StatefulSet](/docs/tasks/run-application/scale-stateful-set/).
870-
* Learn more about [debugging a StatefulSet](/docs/tasks/debug/debug-application/debug-statefulset/).
871-
* Learn more about [deleting a StatefulSet](/docs/tasks/run-application/delete-stateful-set/).
872-
* Learn more about [force deleting StatefulSet Pods](/docs/tasks/run-application/force-delete-stateful-set-pod/).
873-
* Look in the [Helm Charts repository](https://artifacthub.io/)
868+
- Learn more about [scaling a StatefulSet](/docs/tasks/run-application/scale-stateful-set/).
869+
- Learn more about [debugging a StatefulSet](/docs/tasks/debug/debug-application/debug-statefulset/).
870+
- Learn more about [deleting a StatefulSet](/docs/tasks/run-application/delete-stateful-set/).
871+
- Learn more about [force deleting StatefulSet Pods](/docs/tasks/run-application/force-delete-stateful-set-pod/).
872+
- Look in the [Helm Charts repository](https://artifacthub.io/)
874873
for other stateful application examples.
875874
-->
876-
* 进一步了解[为 StatefulSet 扩缩容](/zh-cn/docs/tasks/run-application/scale-stateful-set/)
877-
* 进一步了解[调试 StatefulSet](/zh-cn/docs/tasks/debug/debug-application/debug-statefulset/)
878-
* 进一步了解[删除 StatefulSet](/zh-cn/docs/tasks/run-application/delete-stateful-set/)
879-
* 进一步了解[强制删除 StatefulSet Pod](/zh-cn/docs/tasks/run-application/force-delete-stateful-set-pod/)
880-
*[Helm Charts 仓库](https://artifacthub.io/)中查找其他有状态的应用程序示例。
881-
875+
- 进一步了解[为 StatefulSet 扩缩容](/zh-cn/docs/tasks/run-application/scale-stateful-set/)
876+
- 进一步了解[调试 StatefulSet](/zh-cn/docs/tasks/debug/debug-application/debug-statefulset/)
877+
- 进一步了解[删除 StatefulSet](/zh-cn/docs/tasks/run-application/delete-stateful-set/)
878+
- 进一步了解[强制删除 StatefulSet Pod](/zh-cn/docs/tasks/run-application/force-delete-stateful-set-pod/)
879+
-[Helm Charts 仓库](https://artifacthub.io/)中查找其他有状态的应用程序示例。

0 commit comments

Comments
 (0)