@@ -21,11 +21,14 @@ weight: 30
21
21
<!--
22
22
This page shows how to run a replicated stateful application using a
23
23
[StatefulSet](/docs/concepts/workloads/controllers/statefulset/) controller.
24
- The example is a MySQL single-master topology with multiple slaves running
25
- asynchronous replication.
24
+ This application is a replicated MySQL database. The example topology has a
25
+ single primary server and multiple replicas, using asynchronous row-based
26
+ replication.
26
27
-->
27
28
本页展示如何使用 [ StatefulSet] ( /zh/docs/concepts/workloads/controllers/statefulset/ )
28
- 控制器运行一个有状态的应用程序。此例是一主多从、异步复制的 MySQL 集群。
29
+ 控制器运行一个有状态的应用程序。此例是多副本的 MySQL 数据库。
30
+ 示例应用的拓扑结构有一个主服务器和多个副本,使用异步的基于行(Row-Based)
31
+ 的数据复制。
29
32
30
33
<!--
31
34
**this is not a production configuration**.
@@ -101,12 +104,12 @@ kubectl apply -f https://k8s.io/examples/application/mysql/mysql-configmap.yaml
101
104
102
105
<!--
103
106
This ConfigMap provides `my.cnf` overrides that let you independently control
104
- configuration on the MySQL master and slaves .
105
- In this case, you want the master to be able to serve replication logs to slaves
106
- and you want slaves to reject any writes that don't come via replication.
107
+ configuration on the primary MySQL server and replicas .
108
+ In this case, you want the primary server to be able to serve replication logs to replicas
109
+ and you want repicas to reject any writes that don't come via replication.
107
110
-->
108
111
这个 ConfigMap 提供 ` my.cnf ` 覆盖设置,使你可以独立控制 MySQL 主服务器和从服务器的配置。
109
- 在这里,你希望主服务器能够将复制日志提供给从服务器,并且希望从服务器拒绝任何不是通过
112
+ 在这里,你希望主服务器能够将复制日志提供给副本服务器,并且希望副本服务器拒绝任何不是通过
110
113
复制进行的写操作。
111
114
112
115
<!--
@@ -147,17 +150,17 @@ cluster and namespace.
147
150
<!--
148
151
The Client Service, called `mysql-read`, is a normal Service with its own
149
152
cluster IP that distributes connections across all MySQL Pods that report
150
- being Ready. The set of potential endpoints includes the MySQL master and all
151
- slaves .
153
+ being Ready. The set of potential endpoints includes the primary MySQL server and all
154
+ replicas .
152
155
-->
153
156
客户端服务称为 ` mysql-read ` ,是一种常规服务,具有其自己的集群 IP。
154
157
该集群 IP 在报告就绪的所有MySQL Pod 之间分配连接。
155
- 可能的端点集合包括 MySQL 主节点和所有从节点 。
158
+ 可能的端点集合包括 MySQL 主节点和所有副本节点 。
156
159
157
160
<!--
158
161
Note that only read queries can use the load-balanced Client Service.
159
- Because there is only one MySQL master , clients should connect directly to the
160
- MySQL master Pod (through its DNS entry within the Headless Service) to execute
162
+ Because there is only one primary MySQL server , clients should connect directly to the
163
+ primary MySQL Pod (through its DNS entry within the Headless Service) to execute
161
164
writes.
162
165
-->
163
166
请注意,只有读查询才能使用负载平衡的客户端服务。
@@ -274,38 +277,37 @@ properties.
274
277
而这些 ID 也是需要唯一性、稳定性保证的。
275
278
276
279
<!--
277
- The script in the `init-mysql` container also applies either `master .cnf` or
278
- `slave .cnf` from the ConfigMap by copying the contents into `conf.d`.
279
- Because the example topology consists of a single MySQL master and any number of
280
- slaves , the script simply assigns ordinal `0` to be the master , and everyone
281
- else to be slaves .
280
+ The script in the `init-mysql` container also applies either `primary .cnf` or
281
+ `replica .cnf` from the ConfigMap by copying the contents into `conf.d`.
282
+ Because the example topology consists of a single primary MySQL server and any number of
283
+ replicas , the script simply assigns ordinal `0` to be the primary server , and everyone
284
+ else to be replicas .
282
285
283
286
Combined with the StatefulSet controller's
284
287
[deployment order guarantee](/docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees/),
285
- this ensures the MySQL master is Ready before creating slaves , so they can begin
288
+ this ensures the primary MySQL server is Ready before creating replicas , so they can begin
286
289
replicating.
287
-
288
290
-->
289
291
通过将内容复制到 conf.d 中,` init-mysql ` 容器中的脚本也可以应用 ConfigMap 中的
290
- ` master .cnf` 或 ` slave .cnf` 。
291
- 由于示例部署结构由单个 MySQL 主节点和任意数量的从节点组成 ,因此脚本仅将序数
292
- ` 0 ` 指定为主节点,而将其他所有节点指定为从节点 。
292
+ ` primary .cnf` 或 ` replica .cnf` 。
293
+ 由于示例部署结构由单个 MySQL 主节点和任意数量的副本节点组成 ,因此脚本仅将序数
294
+ ` 0 ` 指定为主节点,而将其他所有节点指定为副本节点 。
293
295
294
296
与 StatefulSet 控制器的
295
297
[ 部署顺序保证] ( /zh/docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees/ )
296
298
相结合,
297
- 可以确保 MySQL 主服务器在创建从服务器之前已准备就绪 ,以便它们可以开始复制。
299
+ 可以确保 MySQL 主服务器在创建副本服务器之前已准备就绪 ,以便它们可以开始复制。
298
300
299
301
<!--
300
302
### Cloning existing data
301
303
302
- In general, when a new Pod joins the set as a slave , it must assume the MySQL
303
- master might already have data on it. It also must assume that the replication
304
+ In general, when a new Pod joins the set as a replica , it must assume the primary MySQL
305
+ server might already have data on it. It also must assume that the replication
304
306
logs might not go all the way back to the beginning of time.
305
307
-->
306
308
### 克隆现有数据
307
309
308
- 通常,当新 Pod 作为从节点加入集合时 ,必须假定 MySQL 主节点可能已经有数据。
310
+ 通常,当新 Pod 作为副本节点加入集合时 ,必须假定 MySQL 主节点可能已经有数据。
309
311
还必须假设复制日志可能不会一直追溯到时间的开始。
310
312
311
313
<!--
@@ -316,11 +318,11 @@ to scale up and down over time, rather than being fixed at its initial size.
316
318
317
319
<!--
318
320
The second Init Container, named `clone-mysql`, performs a clone operation on
319
- a slave Pod the first time it starts up on an empty PersistentVolume.
321
+ a replica Pod the first time it starts up on an empty PersistentVolume.
320
322
That means it copies all existing data from another running Pod,
321
- so its local state is consistent enough to begin replicating from the master.
323
+ so its local state is consistent enough to begin replicating from the primary server.
322
324
-->
323
- 第二个名为 ` clone-mysql ` 的 Init 容器,第一次在带有空 PersistentVolume 的从属 Pod
325
+ 第二个名为 ` clone-mysql ` 的 Init 容器,第一次在带有空 PersistentVolume 的副本 Pod
324
326
上启动时,会在从属 Pod 上执行克隆操作。
325
327
这意味着它将从另一个运行中的 Pod 复制所有现有数据,使此其本地状态足够一致,
326
328
从而可以开始从主服务器复制。
@@ -329,14 +331,14 @@ so its local state is consistent enough to begin replicating from the master.
329
331
MySQL itself does not provide a mechanism to do this, so the example uses a
330
332
popular open-source tool called Percona XtraBackup.
331
333
During the clone, the source MySQL server might suffer reduced performance.
332
- To minimize impact on the MySQL master , the script instructs each Pod to clone
334
+ To minimize impact on the primary MySQL server , the script instructs each Pod to clone
333
335
from the Pod whose ordinal index is one lower.
334
336
This works because the StatefulSet controller always ensures Pod `N` is
335
337
Ready before starting Pod `N+1`.
336
338
-->
337
339
MySQL 本身不提供执行此操作的机制,因此本示例使用了一种流行的开源工具 Percona XtraBackup。
338
340
在克隆期间,源 MySQL 服务器性能可能会受到影响。
339
- 为了最大程度地减少对 MySQL 主节点的影响 ,该脚本指示每个 Pod 从序号较低的 Pod 中克隆。
341
+ 为了最大程度地减少对 MySQL 主服务器的影响 ,该脚本指示每个 Pod 从序号较低的 Pod 中克隆。
340
342
可以这样做的原因是 StatefulSet 控制器始终确保在启动 Pod N + 1 之前 Pod N 已准备就绪。
341
343
342
344
<!--
@@ -356,25 +358,26 @@ MySQL Pod 由运行实际 `mysqld` 服务的 `mysql` 容器和充当
356
358
357
359
<!--
358
360
The `xtrabackup` sidecar looks at the cloned data files and determines if
359
- it's necessary to initialize MySQL replication on the slave .
361
+ it's necessary to initialize MySQL replication on the replica .
360
362
If so, it waits for `mysqld` to be ready and then executes the
361
363
`CHANGE MASTER TO` and `START SLAVE` commands with replication parameters
362
364
extracted from the XtraBackup clone files.
363
365
-->
364
- ` xtrabackup ` sidecar 容器查看克隆的数据文件,并确定是否有必要在从服务器上初始化 MySQL 复制。
366
+ ` xtrabackup ` sidecar 容器查看克隆的数据文件,并确定是否有必要在副本服务器上初始化 MySQL 复制。
365
367
如果是这样,它将等待 ` mysqld ` 准备就绪,然后使用从 XtraBackup 克隆文件中提取的复制参数
366
368
执行 ` CHANGE MASTER TO ` 和 ` START SLAVE ` 命令。
367
369
368
370
<!--
369
- Once a slave begins replication, it remembers its MySQL master and
371
+ Once a replica begins replication, it remembers its primary MySQL server and
370
372
reconnects automatically if the server restarts or the connection dies.
371
- Also, because slaves look for the master at its stable DNS name
372
- (`mysql-0.mysql`), they automatically find the master even if it gets a new
373
+ Also, because replicas look for the primary server at its stable DNS name
374
+ (`mysql-0.mysql`), they automatically find the primary server even if it gets a new
373
375
Pod IP due to being rescheduled.
374
376
-->
375
- 一旦从服务器开始复制后,它会记住其 MySQL 主服务器,并且如果服务器重新启动或连接中断也会自动重新连接。
376
- 另外,因为从服务器会以其稳定的 DNS 名称查找主服务器(` mysql-0.mysql ` ),
377
- 即使由于重新调度而获得新的 Pod IP,他们也会自动找到主服务器。
377
+ 一旦副本服务器开始复制后,它会记住其 MySQL 主服务器,并且如果服务器重新启动或
378
+ 连接中断也会自动重新连接。
379
+ 另外,因为副本服务器会以其稳定的 DNS 名称查找主服务器(` mysql-0.mysql ` ),
380
+ 即使由于重新调度而获得新的 Pod IP,它们也会自动找到主服务器。
378
381
379
382
<!--
380
383
Lastly, after starting replication, the `xtrabackup` container listens for
@@ -389,7 +392,7 @@ case the next Pod loses its PersistentVolumeClaim and needs to redo the clone.
389
392
<!--
390
393
## Sending client traffic
391
394
392
- You can send test queries to the MySQL master (hostname `mysql-0.mysql`)
395
+ You can send test queries to the primary MySQL server (hostname `mysql-0.mysql`)
393
396
by running a temporary container with the `mysql:5.7` image and running the
394
397
`mysql` client binary.
395
398
-->
@@ -478,13 +481,13 @@ it running in another window so you can see the effects of the following steps.
478
481
<!--
479
482
## Simulating Pod and Node downtime
480
483
481
- To demonstrate the increased availability of reading from the pool of slaves
484
+ To demonstrate the increased availability of reading from the pool of replicas
482
485
instead of a single server, keep the `SELECT @@server_id` loop from above
483
486
running while you force a Pod out of the Ready state.
484
487
-->
485
488
## 模拟 Pod 和 Node 的宕机时间
486
489
487
- 为了证明从从节点缓存而不是单个服务器读取数据的可用性提高 ,请在使 Pod 退出 Ready
490
+ 为了证明从副本节点缓存而不是单个服务器读取数据的可用性提高 ,请在使 Pod 退出 Ready
488
491
状态时,保持上述 ` SELECT @@server_id ` 循环一直运行。
489
492
490
493
<!--
@@ -679,14 +682,14 @@ kubectl uncordon <节点名称>
679
682
```
680
683
681
684
<!--
682
- ## Scaling the number of slaves
685
+ ## Scaling the number of replicas
683
686
684
- With MySQL replication, you can scale your read query capacity by adding slaves .
687
+ With MySQL replication, you can scale your read query capacity by adding replicas .
685
688
With StatefulSet, you can do this with a single command:
686
689
-->
687
- ## 扩展从节点数量
690
+ ## 扩展副本节点数量
688
691
689
- 使用 MySQL 复制,你可以通过添加从节点来扩展读取查询的能力 。
692
+ 使用 MySQL 复制,你可以通过添加副本节点来扩展读取查询的能力 。
690
693
使用 StatefulSet,你可以使用单个命令执行此操作:
691
694
692
695
``` shell
0 commit comments