Skip to content

Commit 072d4b4

Browse files
authored
Merge pull request #26291 from tengqm/zh-sync-stateful
[zh] Resync stateful application task
2 parents 8bb2064 + 4c6533f commit 072d4b4

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

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

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ weight: 30
2121
<!--
2222
This page shows how to run a replicated stateful application using a
2323
[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.
2627
-->
2728
本页展示如何使用 [StatefulSet](/zh/docs/concepts/workloads/controllers/statefulset/)
28-
控制器运行一个有状态的应用程序。此例是一主多从、异步复制的 MySQL 集群。
29+
控制器运行一个有状态的应用程序。此例是多副本的 MySQL 数据库。
30+
示例应用的拓扑结构有一个主服务器和多个副本,使用异步的基于行(Row-Based)
31+
的数据复制。
2932

3033
<!--
3134
**this is not a production configuration**.
@@ -101,12 +104,12 @@ kubectl apply -f https://k8s.io/examples/application/mysql/mysql-configmap.yaml
101104

102105
<!--
103106
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.
107110
-->
108111
这个 ConfigMap 提供 `my.cnf` 覆盖设置,使你可以独立控制 MySQL 主服务器和从服务器的配置。
109-
在这里,你希望主服务器能够将复制日志提供给从服务器,并且希望从服务器拒绝任何不是通过
112+
在这里,你希望主服务器能够将复制日志提供给副本服务器,并且希望副本服务器拒绝任何不是通过
110113
复制进行的写操作。
111114

112115
<!--
@@ -147,17 +150,17 @@ cluster and namespace.
147150
<!--
148151
The Client Service, called `mysql-read`, is a normal Service with its own
149152
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.
152155
-->
153156
客户端服务称为 `mysql-read`,是一种常规服务,具有其自己的集群 IP。
154157
该集群 IP 在报告就绪的所有MySQL Pod 之间分配连接。
155-
可能的端点集合包括 MySQL 主节点和所有从节点
158+
可能的端点集合包括 MySQL 主节点和所有副本节点
156159

157160
<!--
158161
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
161164
writes.
162165
-->
163166
请注意,只有读查询才能使用负载平衡的客户端服务。
@@ -274,38 +277,37 @@ properties.
274277
而这些 ID 也是需要唯一性、稳定性保证的。
275278

276279
<!--
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.
282285
283286
Combined with the StatefulSet controller's
284287
[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
286289
replicating.
287-
288290
-->
289291
通过将内容复制到 conf.d 中,`init-mysql` 容器中的脚本也可以应用 ConfigMap 中的
290-
`master.cnf``slave.cnf`
291-
由于示例部署结构由单个 MySQL 主节点和任意数量的从节点组成,因此脚本仅将序数
292-
`0` 指定为主节点,而将其他所有节点指定为从节点
292+
`primary.cnf``replica.cnf`
293+
由于示例部署结构由单个 MySQL 主节点和任意数量的副本节点组成,因此脚本仅将序数
294+
`0` 指定为主节点,而将其他所有节点指定为副本节点
293295

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

299301
<!--
300302
### Cloning existing data
301303
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
304306
logs might not go all the way back to the beginning of time.
305307
-->
306308
### 克隆现有数据
307309

308-
通常,当新 Pod 作为从节点加入集合时,必须假定 MySQL 主节点可能已经有数据。
310+
通常,当新 Pod 作为副本节点加入集合时,必须假定 MySQL 主节点可能已经有数据。
309311
还必须假设复制日志可能不会一直追溯到时间的开始。
310312

311313
<!--
@@ -316,11 +318,11 @@ to scale up and down over time, rather than being fixed at its initial size.
316318

317319
<!--
318320
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.
320322
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.
322324
-->
323-
第二个名为 `clone-mysql` 的 Init 容器,第一次在带有空 PersistentVolume 的从属 Pod
325+
第二个名为 `clone-mysql` 的 Init 容器,第一次在带有空 PersistentVolume 的副本 Pod
324326
上启动时,会在从属 Pod 上执行克隆操作。
325327
这意味着它将从另一个运行中的 Pod 复制所有现有数据,使此其本地状态足够一致,
326328
从而可以开始从主服务器复制。
@@ -329,14 +331,14 @@ so its local state is consistent enough to begin replicating from the master.
329331
MySQL itself does not provide a mechanism to do this, so the example uses a
330332
popular open-source tool called Percona XtraBackup.
331333
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
333335
from the Pod whose ordinal index is one lower.
334336
This works because the StatefulSet controller always ensures Pod `N` is
335337
Ready before starting Pod `N+1`.
336338
-->
337339
MySQL 本身不提供执行此操作的机制,因此本示例使用了一种流行的开源工具 Percona XtraBackup。
338340
在克隆期间,源 MySQL 服务器性能可能会受到影响。
339-
为了最大程度地减少对 MySQL 主节点的影响,该脚本指示每个 Pod 从序号较低的 Pod 中克隆。
341+
为了最大程度地减少对 MySQL 主服务器的影响,该脚本指示每个 Pod 从序号较低的 Pod 中克隆。
340342
可以这样做的原因是 StatefulSet 控制器始终确保在启动 Pod N + 1 之前 Pod N 已准备就绪。
341343

342344
<!--
@@ -356,25 +358,26 @@ MySQL Pod 由运行实际 `mysqld` 服务的 `mysql` 容器和充当
356358

357359
<!--
358360
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.
360362
If so, it waits for `mysqld` to be ready and then executes the
361363
`CHANGE MASTER TO` and `START SLAVE` commands with replication parameters
362364
extracted from the XtraBackup clone files.
363365
-->
364-
`xtrabackup` sidecar 容器查看克隆的数据文件,并确定是否有必要在从服务器上初始化 MySQL 复制。
366+
`xtrabackup` sidecar 容器查看克隆的数据文件,并确定是否有必要在副本服务器上初始化 MySQL 复制。
365367
如果是这样,它将等待 `mysqld` 准备就绪,然后使用从 XtraBackup 克隆文件中提取的复制参数
366368
执行 `CHANGE MASTER TO``START SLAVE` 命令。
367369

368370
<!--
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
370372
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
373375
Pod IP due to being rescheduled.
374376
-->
375-
一旦从服务器开始复制后,它会记住其 MySQL 主服务器,并且如果服务器重新启动或连接中断也会自动重新连接。
376-
另外,因为从服务器会以其稳定的 DNS 名称查找主服务器(`mysql-0.mysql`),
377-
即使由于重新调度而获得新的 Pod IP,他们也会自动找到主服务器。
377+
一旦副本服务器开始复制后,它会记住其 MySQL 主服务器,并且如果服务器重新启动或
378+
连接中断也会自动重新连接。
379+
另外,因为副本服务器会以其稳定的 DNS 名称查找主服务器(`mysql-0.mysql`),
380+
即使由于重新调度而获得新的 Pod IP,它们也会自动找到主服务器。
378381

379382
<!--
380383
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.
389392
<!--
390393
## Sending client traffic
391394
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`)
393396
by running a temporary container with the `mysql:5.7` image and running the
394397
`mysql` client binary.
395398
-->
@@ -478,13 +481,13 @@ it running in another window so you can see the effects of the following steps.
478481
<!--
479482
## Simulating Pod and Node downtime
480483
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
482485
instead of a single server, keep the `SELECT @@server_id` loop from above
483486
running while you force a Pod out of the Ready state.
484487
-->
485488
## 模拟 Pod 和 Node 的宕机时间
486489

487-
为了证明从从节点缓存而不是单个服务器读取数据的可用性提高,请在使 Pod 退出 Ready
490+
为了证明从副本节点缓存而不是单个服务器读取数据的可用性提高,请在使 Pod 退出 Ready
488491
状态时,保持上述 `SELECT @@server_id` 循环一直运行。
489492

490493
<!--
@@ -679,14 +682,14 @@ kubectl uncordon <节点名称>
679682
```
680683

681684
<!--
682-
## Scaling the number of slaves
685+
## Scaling the number of replicas
683686
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.
685688
With StatefulSet, you can do this with a single command:
686689
-->
687-
## 扩展从节点数量
690+
## 扩展副本节点数量
688691

689-
使用 MySQL 复制,你可以通过添加从节点来扩展读取查询的能力
692+
使用 MySQL 复制,你可以通过添加副本节点来扩展读取查询的能力
690693
使用 StatefulSet,你可以使用单个命令执行此操作:
691694

692695
```shell

0 commit comments

Comments
 (0)