Skip to content

Commit f2a78fa

Browse files
authored
Merge pull request #23119 from devries/statefulset-mysql-language
Replace master/slave with primary/replica in MySQL StatefulSet example
2 parents c7545c1 + b7f8f82 commit f2a78fa

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ weight: 30
1515

1616
This page shows how to run a replicated stateful application using a
1717
[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.
2021

2122
{{< note >}}
2223
**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
6970
```
7071

7172
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.
7576

7677
There's nothing special about the ConfigMap itself that causes different
7778
portions to apply to different Pods.
@@ -96,12 +97,12 @@ cluster and namespace.
9697

9798
The Client Service, called `mysql-read`, is a normal Service with its own
9899
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.
101102

102103
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
105106
writes.
106107

107108
### StatefulSet
@@ -167,33 +168,33 @@ This translates the unique, stable identity provided by the StatefulSet
167168
controller into the domain of MySQL server IDs, which require the same
168169
properties.
169170

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.
175176
Combined with the StatefulSet controller's
176177
[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
178179
replicating.
179180

180181
### Cloning existing data
181182

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
184185
logs might not go all the way back to the beginning of time.
185186
These conservative assumptions are the key to allow a running StatefulSet
186187
to scale up and down over time, rather than being fixed at its initial size.
187188

188189
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.
190191
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.
192193

193194
MySQL itself does not provide a mechanism to do this, so the example uses a
194195
popular open-source tool called Percona XtraBackup.
195196
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
197198
from the Pod whose ordinal index is one lower.
198199
This works because the StatefulSet controller always ensures Pod `N` is
199200
Ready before starting Pod `N+1`.
@@ -206,15 +207,15 @@ server, and an `xtrabackup` container that acts as a
206207
[sidecar](https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns).
207208

208209
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.
210211
If so, it waits for `mysqld` to be ready and then executes the
211212
`CHANGE MASTER TO` and `START SLAVE` commands with replication parameters
212213
extracted from the XtraBackup clone files.
213214

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
215216
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
218219
Pod IP due to being rescheduled.
219220

220221
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.
224225

225226
## Sending client traffic
226227

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`)
228229
by running a temporary container with the `mysql:5.7` image and running the
229230
`mysql` client binary.
230231

@@ -291,7 +292,7 @@ it running in another window so you can see the effects of the following steps.
291292

292293
## Simulating Pod and Node downtime
293294

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
295296
instead of a single server, keep the `SELECT @@server_id` loop from above
296297
running while you force a Pod out of the Ready state.
297298

@@ -409,9 +410,9 @@ Now uncordon the Node to return it to a normal state:
409410
kubectl uncordon <node-name>
410411
```
411412

412-
## Scaling the number of slaves
413+
## Scaling the number of replicas
413414

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.
415416
With StatefulSet, you can do this with a single command:
416417

417418
```shell

content/en/examples/application/mysql/mysql-configmap.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ metadata:
55
labels:
66
app: mysql
77
data:
8-
master.cnf: |
9-
# Apply this config only on the master.
8+
primary.cnf: |
9+
# Apply this config only on the primary.
1010
[mysqld]
1111
log-bin
12-
slave.cnf: |
13-
# Apply this config only on slaves.
12+
replica.cnf: |
13+
# Apply this config only on replicas.
1414
[mysqld]
1515
super-read-only
1616

content/en/examples/application/mysql/mysql-services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
app: mysql
1515
---
1616
# Client service for connecting to any MySQL instance for reads.
17-
# For writes, you must instead connect to the master: mysql-0.mysql.
17+
# For writes, you must instead connect to the primary: mysql-0.mysql.
1818
apiVersion: v1
1919
kind: Service
2020
metadata:

content/en/examples/application/mysql/mysql-statefulset.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ spec:
2929
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
3030
# Copy appropriate conf.d files from config-map to emptyDir.
3131
if [[ $ordinal -eq 0 ]]; then
32-
cp /mnt/config-map/master.cnf /mnt/conf.d/
32+
cp /mnt/config-map/primary.cnf /mnt/conf.d/
3333
else
34-
cp /mnt/config-map/slave.cnf /mnt/conf.d/
34+
cp /mnt/config-map/replica.cnf /mnt/conf.d/
3535
fi
3636
volumeMounts:
3737
- name: conf
@@ -47,7 +47,7 @@ spec:
4747
set -ex
4848
# Skip the clone if data already exists.
4949
[[ -d /var/lib/mysql/mysql ]] && exit 0
50-
# Skip the clone on master (ordinal index 0).
50+
# Skip the clone on primary (ordinal index 0).
5151
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
5252
ordinal=${BASH_REMATCH[1]}
5353
[[ $ordinal -eq 0 ]] && exit 0
@@ -108,12 +108,12 @@ spec:
108108
# Determine binlog position of cloned data, if any.
109109
if [[ -f xtrabackup_slave_info && "x$(<xtrabackup_slave_info)" != "x" ]]; then
110110
# XtraBackup already generated a partial "CHANGE MASTER TO" query
111-
# because we're cloning from an existing slave. (Need to remove the tailing semicolon!)
111+
# because we're cloning from an existing replica. (Need to remove the tailing semicolon!)
112112
cat xtrabackup_slave_info | sed -E 's/;$//g' > change_master_to.sql.in
113113
# Ignore xtrabackup_binlog_info in this case (it's useless).
114114
rm -f xtrabackup_slave_info xtrabackup_binlog_info
115115
elif [[ -f xtrabackup_binlog_info ]]; then
116-
# We're cloning directly from master. Parse binlog position.
116+
# We're cloning directly from primary. Parse binlog position.
117117
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
118118
rm -f xtrabackup_binlog_info xtrabackup_slave_info
119119
echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\

0 commit comments

Comments
 (0)