@@ -15,8 +15,9 @@ weight: 30
15
15
16
16
This page shows how to run a replicated stateful application using a
17
17
[ StatefulSet] ( /docs/concepts/workloads/controllers/statefulset/ ) controller.
18
- The example is a MySQL single-master topology with multiple slaves running
19
- asynchronous replication.
18
+ This application is a replicated MySQL database. The example topology has a
19
+ single primary server and multiple replicas, using asynchronous row-based
20
+ replication.
20
21
21
22
{{< note >}}
22
23
** This is not a production configuration** . MySQL settings remain on insecure defaults to keep the focus
@@ -69,9 +70,9 @@ kubectl apply -f https://k8s.io/examples/application/mysql/mysql-configmap.yaml
69
70
```
70
71
71
72
This ConfigMap provides ` my.cnf ` overrides that let you independently control
72
- configuration on the MySQL master and slaves .
73
- In this case, you want the master to be able to serve replication logs to slaves
74
- and you want slaves to reject any writes that don't come via replication.
73
+ configuration on the primary MySQL server and replicas .
74
+ In this case, you want the primary server to be able to serve replication logs to replicas
75
+ and you want replicas to reject any writes that don't come via replication.
75
76
76
77
There's nothing special about the ConfigMap itself that causes different
77
78
portions to apply to different Pods.
@@ -96,12 +97,12 @@ cluster and namespace.
96
97
97
98
The Client Service, called ` mysql-read ` , is a normal Service with its own
98
99
cluster IP that distributes connections across all MySQL Pods that report
99
- being Ready. The set of potential endpoints includes the MySQL master and all
100
- slaves .
100
+ being Ready. The set of potential endpoints includes the primary MySQL server and all
101
+ replicas .
101
102
102
103
Note that only read queries can use the load-balanced Client Service.
103
- Because there is only one MySQL master , clients should connect directly to the
104
- MySQL master Pod (through its DNS entry within the Headless Service) to execute
104
+ Because there is only one primary MySQL server , clients should connect directly to the
105
+ primary MySQL Pod (through its DNS entry within the Headless Service) to execute
105
106
writes.
106
107
107
108
### StatefulSet
@@ -167,33 +168,33 @@ This translates the unique, stable identity provided by the StatefulSet
167
168
controller into the domain of MySQL server IDs, which require the same
168
169
properties.
169
170
170
- The script in the ` init-mysql ` container also applies either ` master .cnf` or
171
- ` slave .cnf` from the ConfigMap by copying the contents into ` conf.d ` .
172
- Because the example topology consists of a single MySQL master and any number of
173
- slaves , the script simply assigns ordinal ` 0 ` to be the master , and everyone
174
- else to be slaves .
171
+ The script in the ` init-mysql ` container also applies either ` primary .cnf` or
172
+ ` replica .cnf` from the ConfigMap by copying the contents into ` conf.d ` .
173
+ Because the example topology consists of a single primary MySQL server and any number of
174
+ replicas , the script simply assigns ordinal ` 0 ` to be the primary server , and everyone
175
+ else to be replicas .
175
176
Combined with the StatefulSet controller's
176
177
[ deployment order guarantee] ( /docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees/ ) ,
177
- this ensures the MySQL master is Ready before creating slaves , so they can begin
178
+ this ensures the primary MySQL server is Ready before creating replicas , so they can begin
178
179
replicating.
179
180
180
181
### Cloning existing data
181
182
182
- In general, when a new Pod joins the set as a slave , it must assume the MySQL
183
- master might already have data on it. It also must assume that the replication
183
+ In general, when a new Pod joins the set as a replica , it must assume the primary MySQL
184
+ server might already have data on it. It also must assume that the replication
184
185
logs might not go all the way back to the beginning of time.
185
186
These conservative assumptions are the key to allow a running StatefulSet
186
187
to scale up and down over time, rather than being fixed at its initial size.
187
188
188
189
The second Init Container, named ` clone-mysql ` , performs a clone operation on
189
- a slave Pod the first time it starts up on an empty PersistentVolume.
190
+ a replica Pod the first time it starts up on an empty PersistentVolume.
190
191
That means it copies all existing data from another running Pod,
191
- so its local state is consistent enough to begin replicating from the master .
192
+ so its local state is consistent enough to begin replicating from the primary server .
192
193
193
194
MySQL itself does not provide a mechanism to do this, so the example uses a
194
195
popular open-source tool called Percona XtraBackup.
195
196
During the clone, the source MySQL server might suffer reduced performance.
196
- To minimize impact on the MySQL master , the script instructs each Pod to clone
197
+ To minimize impact on the primary MySQL server , the script instructs each Pod to clone
197
198
from the Pod whose ordinal index is one lower.
198
199
This works because the StatefulSet controller always ensures Pod ` N ` is
199
200
Ready before starting Pod ` N+1 ` .
@@ -206,15 +207,15 @@ server, and an `xtrabackup` container that acts as a
206
207
[ sidecar] ( https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns ) .
207
208
208
209
The ` xtrabackup ` sidecar looks at the cloned data files and determines if
209
- it's necessary to initialize MySQL replication on the slave .
210
+ it's necessary to initialize MySQL replication on the replica .
210
211
If so, it waits for ` mysqld ` to be ready and then executes the
211
212
` CHANGE MASTER TO ` and ` START SLAVE ` commands with replication parameters
212
213
extracted from the XtraBackup clone files.
213
214
214
- Once a slave begins replication, it remembers its MySQL master and
215
+ Once a replica begins replication, it remembers its primary MySQL server and
215
216
reconnects automatically if the server restarts or the connection dies.
216
- Also, because slaves look for the master at its stable DNS name
217
- (` mysql-0.mysql ` ), they automatically find the master even if it gets a new
217
+ Also, because replicas look for the primary server at its stable DNS name
218
+ (` mysql-0.mysql ` ), they automatically find the primary server even if it gets a new
218
219
Pod IP due to being rescheduled.
219
220
220
221
Lastly, after starting replication, the ` xtrabackup ` container listens for
@@ -224,7 +225,7 @@ case the next Pod loses its PersistentVolumeClaim and needs to redo the clone.
224
225
225
226
## Sending client traffic
226
227
227
- You can send test queries to the MySQL master (hostname ` mysql-0.mysql ` )
228
+ You can send test queries to the primary MySQL server (hostname ` mysql-0.mysql ` )
228
229
by running a temporary container with the ` mysql:5.7 ` image and running the
229
230
` mysql ` client binary.
230
231
@@ -291,7 +292,7 @@ it running in another window so you can see the effects of the following steps.
291
292
292
293
## Simulating Pod and Node downtime
293
294
294
- To demonstrate the increased availability of reading from the pool of slaves
295
+ To demonstrate the increased availability of reading from the pool of replicas
295
296
instead of a single server, keep the ` SELECT @@server_id ` loop from above
296
297
running while you force a Pod out of the Ready state.
297
298
@@ -409,9 +410,9 @@ Now uncordon the Node to return it to a normal state:
409
410
kubectl uncordon < node-name>
410
411
```
411
412
412
- ## Scaling the number of slaves
413
+ ## Scaling the number of replicas
413
414
414
- With MySQL replication, you can scale your read query capacity by adding slaves .
415
+ With MySQL replication, you can scale your read query capacity by adding replicas .
415
416
With StatefulSet, you can do this with a single command:
416
417
417
418
``` shell
0 commit comments