@@ -30,53 +30,52 @@ replication.
30
30
示例应用的拓扑结构有一个主服务器和多个副本,使用异步的基于行(Row-Based)
31
31
的数据复制。
32
32
33
+ {{< note >}}
33
34
<!--
34
35
**This is not a production configuration**. MySQL settings remain on insecure defaults to keep the focus
35
36
on general patterns for running stateful applications in Kubernetes.
36
37
-->
37
- {{< note >}}
38
38
** 这一配置不适合生产环境。**
39
39
MySQL 设置都使用的是不安全的默认值,这是因为我们想把重点放在 Kubernetes
40
40
中运行有状态应用程序的一般模式上。
41
41
{{< /note >}}
42
42
43
43
## {{% heading "prerequisites" %}}
44
44
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" >}}
48
47
<!--
49
- * This tutorial assumes you are familiar with
48
+ - This tutorial assumes you are familiar with
50
49
[PersistentVolumes](/docs/concepts/storage/persistent-volumes/)
51
50
and [StatefulSets](/docs/concepts/workloads/controllers/statefulset/),
52
51
as well as other core concepts like [Pods](/docs/concepts/workloads/pods/),
53
52
[Services](/docs/concepts/services-networking/service/), and
54
53
[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
56
55
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.
58
57
-->
59
- * 本教程假定你熟悉
58
+ - 本教程假定你熟悉
60
59
[ 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/ ) ,
62
61
以及其他核心概念,例如 [ 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
+ - 你正在使用默认命名空间或不包含任何冲突对象的另一个命名空间。
67
66
68
67
## {{% heading "objectives" %}}
69
68
70
69
<!--
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.
75
74
-->
76
- * 使用 StatefulSet 部署多副本 MySQL 拓扑架构。
77
- * 发送 MySQL 客户端请求
78
- * 观察对宕机的抵抗力
79
- * 扩缩 StatefulSet 的规模
75
+ - 使用 StatefulSet 部署多副本 MySQL 拓扑架构。
76
+ - 发送 MySQL 客户端请求。
77
+ - 观察对宕机的抵抗力。
78
+ - 扩缩 StatefulSet 的规模。
80
79
81
80
<!-- lessoncontent -->
82
81
@@ -119,7 +118,7 @@ and you want replicas to reject any writes that don't come via replication.
119
118
There's nothing special about the ConfigMap itself that causes different
120
119
portions to apply to different Pods.
121
120
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.
123
122
-->
124
123
ConfigMap 本身没有什么特别之处,因而也不会出现不同部分应用于不同的 Pod 的情况。
125
124
每个 Pod 都会在初始化时基于 StatefulSet 控制器提供的信息决定要查看的部分。
@@ -145,7 +144,7 @@ The headless Service provides a home for the DNS entries that the StatefulSet
145
144
Pod that's part of the set.
146
145
Because the headless Service is named `mysql`, the Pods are accessible by
147
146
resolving `<pod-name>.mysql` from within any other Pod in the same Kubernetes
148
- cluster and namespace.
147
+ cluster and namespace.
149
148
-->
150
149
这个无头 Service 给 StatefulSet {{< glossary_tooltip text="控制器" term_id="controller" >}}
151
150
为集合中每个 Pod 创建的 DNS 条目提供了一个宿主。
@@ -156,7 +155,7 @@ cluster and namespace.
156
155
The client Service, called `mysql-read`, is a normal Service with its own
157
156
cluster IP that distributes connections across all MySQL Pods that report
158
157
being Ready. The set of potential endpoints includes the primary MySQL server and all
159
- replicas.
158
+ replicas.
160
159
-->
161
160
客户端 Service 称为 ` mysql-read ` ,是一种常规 Service,具有其自己的集群 IP。
162
161
该集群 IP 在报告就绪的所有 MySQL Pod 之间分配连接。
@@ -166,7 +165,7 @@ replicas.
166
165
Note that only read queries can use the load-balanced client Service.
167
166
Because there is only one primary MySQL server, clients should connect directly to the
168
167
primary MySQL Pod (through its DNS entry within the headless Service) to execute
169
- writes.
168
+ writes.
170
169
-->
171
170
请注意,只有读查询才能使用负载平衡的客户端 Service。
172
171
因为只有一个 MySQL 主服务器,所以客户端应直接连接到 MySQL 主服务器 Pod
@@ -175,7 +174,7 @@ writes.
175
174
<!--
176
175
### Create the StatefulSet {#statefulset}
177
176
178
- Finally, create the StatefulSet from the following YAML configuration file:
177
+ Finally, create the StatefulSet from the following YAML configuration file:
179
178
-->
180
179
### 创建 StatefulSet {#statefulset}
181
180
@@ -218,8 +217,8 @@ Press **Ctrl+C** to cancel the watch.
218
217
If you don't see any progress, make sure you have a dynamic PersistentVolume
219
218
provisioner enabled, as mentioned in the [prerequisites](#before-you-begin).
220
219
-->
221
- 如果你看不到任何进度,确保已启用[ 前提条件] ( #准备开始 )
222
- 中提到的动态 PersistentVolume 制备程序 。
220
+ 如果你看不到任何进度,确保已启用[ 前提条件] ( #准备开始 ) 中提到的动态
221
+ PersistentVolume 制备器 。
223
222
{{< /note >}}
224
223
225
224
<!--
@@ -237,7 +236,7 @@ The StatefulSet controller starts Pods one at a time, in order by their
237
236
ordinal index.
238
237
It waits until each Pod reports being Ready before starting the next one.
239
238
-->
240
- ## 了解有状态的 Pod 初始化
239
+ ## 了解有状态的 Pod 初始化 {#understanding-stateful-pod-init}
241
240
242
241
StatefulSet 控制器按序数索引顺序地每次启动一个 Pod。
243
242
它一直等到每个 Pod 报告就绪才再启动下一个 Pod。
@@ -263,16 +262,16 @@ Before starting any of the containers in the Pod spec, the Pod first runs any
263
262
[init Containers](/docs/concepts/workloads/pods/init-containers/)
264
263
in the order defined.
265
264
-->
266
- ### 生成配置
265
+ ### 生成配置 {#generating-config}
267
266
268
267
在启动 Pod 规约中的任何容器之前,Pod 首先按顺序运行所有的
269
- [ 初始化容器 ] ( /zh-cn/docs/concepts/workloads/pods/init-containers/ ) 。
268
+ [ Init 容器 ] ( /zh-cn/docs/concepts/workloads/pods/init-containers/ ) 。
270
269
271
270
<!--
272
271
The first init container, named `init-mysql`, generates special MySQL config
273
272
files based on the ordinal index.
274
273
-->
275
- 第一个名为 ` init-mysql ` 的初始化容器根据序号索引生成特殊的 MySQL 配置文件。
274
+ 第一个名为 ` init-mysql ` 的 Init 容器根据序号索引生成特殊的 MySQL 配置文件。
276
275
277
276
<!--
278
277
The script determines its own ordinal index by extracting it from the end of
@@ -304,9 +303,8 @@ replicating.
304
303
由于示例部署结构由单个 MySQL 主节点和任意数量的副本节点组成,
305
304
因此脚本仅将序数 ` 0 ` 指定为主节点,而将其他所有节点指定为副本节点。
306
305
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 ) 相结合,
310
308
可以确保 MySQL 主服务器在创建副本服务器之前已准备就绪,以便它们可以开始复制。
311
309
312
310
<!--
@@ -316,7 +314,7 @@ In general, when a new Pod joins the set as a replica, it must assume the primar
316
314
server might already have data on it. It also must assume that the replication
317
315
logs might not go all the way back to the beginning of time.
318
316
-->
319
- ### 克隆现有数据
317
+ ### 克隆现有数据 {#cloning-existing-data}
320
318
321
319
通常,当新 Pod 作为副本节点加入集合时,必须假定 MySQL 主节点可能已经有数据。
322
320
还必须假设复制日志可能不会一直追溯到时间的开始。
@@ -333,7 +331,7 @@ a replica Pod the first time it starts up on an empty PersistentVolume.
333
331
That means it copies all existing data from another running Pod,
334
332
so its local state is consistent enough to begin replicating from the primary server.
335
333
-->
336
- 第二个名为 ` clone-mysql ` 的初始化容器 ,第一次在带有空 PersistentVolume 的副本 Pod
334
+ 第二个名为 ` clone-mysql ` 的 Init 容器 ,第一次在带有空 PersistentVolume 的副本 Pod
337
335
上启动时,会在从属 Pod 上执行克隆操作。
338
336
这意味着它将从另一个运行中的 Pod 复制所有现有数据,使此其本地状态足够一致,
339
337
从而可以开始从主服务器复制。
@@ -350,7 +348,7 @@ Ready before starting Pod `N+1`.
350
348
MySQL 本身不提供执行此操作的机制,因此本示例使用了一种流行的开源工具 Percona XtraBackup。
351
349
在克隆期间,源 MySQL 服务器性能可能会受到影响。
352
350
为了最大程度地减少对 MySQL 主服务器的影响,该脚本指示每个 Pod 从序号较低的 Pod 中克隆。
353
- 可以这样做的原因是 StatefulSet 控制器始终确保在启动 Pod ` N + 1 ` 之前 Pod ` N ` 已准备就绪。
351
+ 可以这样做的原因是 StatefulSet 控制器始终确保在启动 Pod ` N+ 1 ` 之前 Pod ` N ` 已准备就绪。
354
352
355
353
<!--
356
354
### Starting replication
@@ -360,9 +358,9 @@ The MySQL Pods consist of a `mysql` container that runs the actual `mysqld`
360
358
server, and an `xtrabackup` container that acts as a
361
359
[sidecar](/blog/2015/06/the-distributed-system-toolkit-patterns).
362
360
-->
363
- ### 开始复制
361
+ ### 开始复制 {#starting-replication}
364
362
365
- 初始化容器成功完成后 ,应用容器将运行。MySQL Pod 由运行实际 ` mysqld ` 服务的 ` mysql `
363
+ Init 容器成功完成后 ,应用容器将运行。MySQL Pod 由运行实际 ` mysqld ` 服务的 ` mysql `
366
364
容器和充当[ 辅助工具] ( /blog/2015/06/the-distributed-system-toolkit-patterns ) 的
367
365
xtrabackup 容器组成。
368
366
@@ -405,7 +403,7 @@ You can send test queries to the primary MySQL server (hostname `mysql-0.mysql`)
405
403
by running a temporary container with the `mysql:5.7` image and running the
406
404
`mysql` client binary.
407
405
-->
408
- ## 发送客户端请求
406
+ ## 发送客户端请求 {#sending-client-traffic}
409
407
410
408
你可以通过运行带有 ` mysql:5.7 ` 镜像的临时容器并运行 ` mysql ` 客户端二进制文件,
411
409
将测试查询发送到 MySQL 主服务器(主机名 ` mysql-0.mysql ` )。
@@ -504,9 +502,9 @@ running while you force a Pod out of the Ready state.
504
502
505
503
The [readiness probe](/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes)
506
504
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.
508
506
-->
509
- ### 破坏就绪态探测
507
+ ### 破坏就绪态探测 {#break-readiness-probe}
510
508
511
509
` mysql ` 容器的[ 就绪态探测] ( /zh-cn/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes )
512
510
运行命令 ` 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
567
565
### Delete Pods
568
566
569
567
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.
571
569
-->
572
- ### 删除 Pods
570
+ ### 删除 Pod {#delete-pods}
573
571
574
572
如果删除了 Pod,则 StatefulSet 还会重新创建 Pod,类似于 ReplicaSet 对无状态 Pod 所做的操作。
575
573
@@ -582,7 +580,7 @@ The StatefulSet controller notices that no `mysql-2` Pod exists anymore,
582
580
and creates a new one with the same name and linked to the same
583
581
PersistentVolumeClaim.
584
582
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.
586
584
-->
587
585
StatefulSet 控制器注意到不再存在 ` mysql-2 ` Pod,于是创建一个具有相同名称并链接到相同
588
586
PersistentVolumeClaim 的新 Pod。
@@ -593,7 +591,7 @@ PersistentVolumeClaim 的新 Pod。
593
591
594
592
If your Kubernetes cluster has multiple Nodes, you can simulate Node downtime
595
593
(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).
597
595
-->
598
596
### 腾空节点 {#drain-a-node}
599
597
@@ -628,15 +626,14 @@ Replace `<node-name>` with the name of the Node you found in the last step.
628
626
接下来,通过运行以下命令腾空节点,该命令将其保护起来,以使新的 Pod 不能调度到该节点,
629
627
然后逐出所有现有的 Pod。将 ` <节点名称> ` 替换为在上一步中找到的节点名称。
630
628
631
-
632
629
{{< caution >}}
633
630
<!--
634
- Draining a Node can impact other workloads and applications
631
+ Draining a Node can impact other workloads and applications
635
632
running on the same node. Only perform the following step in a test
636
633
cluster.
637
634
-->
638
635
腾空一个 Node 可能影响到在该节点上运行的其他负载和应用。
639
- 只应在测试集群上执行下列步骤
636
+ 只应在测试集群上执行下列步骤。
640
637
{{< /caution >}}
641
638
642
639
<!--
@@ -704,7 +701,7 @@ When you use MySQL replication, you can scale your read query capacity by
704
701
adding replicas.
705
702
For a StatefulSet, you can achieve this with a single command:
706
703
-->
707
- ## 扩展副本节点数量
704
+ ## 扩展副本节点数量 {#scaling-number-of-replicas}
708
705
709
706
使用 MySQL 复制时,你可以通过添加副本节点来扩展读取查询的能力。
710
707
对于 StatefulSet,你可以使用单个命令实现此目的:
@@ -729,7 +726,7 @@ the `SELECT @@server_id` loop output.
729
726
You can also verify that these new servers have the data you added before they
730
727
existed:
731
728
-->
732
- 一旦 Pod 启动,你应该看到服务器 IDs ` 103 ` 和 ` 104 ` 开始出现在 ` SELECT @@server_id `
729
+ 一旦 Pod 启动,你应该看到服务器 ID ` 103 ` 和 ` 104 ` 开始出现在 ` SELECT @@server_id `
733
730
循环输出中。
734
731
735
732
你还可以验证这些新服务器在存在之前已添加了数据:
@@ -783,7 +780,7 @@ kubectl get pvc -l app=mysql
783
780
Which shows that all 5 PVCs still exist, despite having scaled the
784
781
StatefulSet down to 3:
785
782
-->
786
- 这表明,尽管将 StatefulSet 缩小为3,所有5个 PVC 仍然存在:
783
+ 这表明,尽管将 StatefulSet 缩小为 3,所有 5 个 PVC 仍然存在:
787
784
788
785
```
789
786
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
@@ -829,13 +826,15 @@ kubectl delete pvc data-mysql-4
829
826
1. Verify that the Pods disappear.
830
827
They might take some time to finish terminating.
831
828
-->
832
- 3 . 验证 Pod 消失。他们可能需要一些时间才能完成终止 。
829
+ 3 . 验证 Pod 消失。它们可能需要一些时间才能完成终止 。
833
830
834
831
``` shell
835
832
kubectl get pods -l app=mysql
836
833
```
837
834
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
+ -->
839
838
当上述命令返回如下内容时,你就知道 Pod 已终止:
840
839
841
840
```
@@ -859,23 +858,22 @@ kubectl delete pvc data-mysql-4
859
858
Some dynamic provisioners (such as those for EBS and PD) also release the
860
859
underlying resources upon deleting the PersistentVolumes.
861
860
-->
862
- 5 . 如果你手动供应 PersistentVolume,则还需要手动删除它们,并释放下层资源。
863
- 如果你使用了动态预配器 ,当得知你删除 PersistentVolumeClaim 时,它将自动删除 PersistentVolume。
864
- 一些动态预配器 (例如用于 EBS 和 PD 的预配器 )也会在删除 PersistentVolume 时释放下层资源。
861
+ 5 . 如果你手动制备 PersistentVolume,则还需要手动删除它们,并释放下层资源。
862
+ 如果你使用了动态制备器 ,当得知你删除 PersistentVolumeClaim 时,它将自动删除 PersistentVolume。
863
+ 一些动态制备器 (例如用于 EBS 和 PD 的制备器 )也会在删除 PersistentVolume 时释放下层资源。
865
864
866
865
## {{% heading "whatsnext" %}}
867
866
868
867
<!--
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/)
874
873
for other stateful application examples.
875
874
-->
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