Demonstrate master/slave ConfigMap entries.
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
# Create a ConfigMap resource from this file:
|
|
||||||
# kubectl create configmap mysql --from-file=./my.cnf
|
|
||||||
[mysqld]
|
|
||||||
log-bin
|
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: mysql
|
||||||
|
labels:
|
||||||
|
app: mysql
|
||||||
|
data:
|
||||||
|
master.cnf: |
|
||||||
|
# Apply this config only on the master.
|
||||||
|
[mysqld]
|
||||||
|
log-bin
|
||||||
|
slave.cnf: |
|
||||||
|
# Apply this config only on slaves.
|
||||||
|
[mysqld]
|
||||||
|
super-read-only
|
||||||
|
|
||||||
@@ -18,13 +18,18 @@ spec:
|
|||||||
set -ex\n
|
set -ex\n
|
||||||
# mysqld --initialize expects an empty data dir.\n
|
# mysqld --initialize expects an empty data dir.\n
|
||||||
rm -rf /mnt/data/lost+found\n
|
rm -rf /mnt/data/lost+found\n
|
||||||
# Copy conf.d from config-map to emptyDir.\n
|
|
||||||
cp /mnt/config-map/* /mnt/conf.d/\n
|
|
||||||
# Generate mysql server-id from pod ordinal index.\n
|
# Generate mysql server-id from pod ordinal index.\n
|
||||||
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1\n
|
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1\n
|
||||||
|
ordinal=${BASH_REMATCH[1]}\n
|
||||||
echo [mysqld] > /mnt/conf.d/server-id.cnf\n
|
echo [mysqld] > /mnt/conf.d/server-id.cnf\n
|
||||||
# Add an offset to avoid reserved server-id=0 value.\n
|
# Add an offset to avoid reserved server-id=0 value.\n
|
||||||
echo server-id=$((100 + ${BASH_REMATCH[1]})) >> /mnt/conf.d/server-id.cnf\n
|
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf\n
|
||||||
|
# Copy appropriate conf.d files from config-map to emptyDir.\n
|
||||||
|
if [[ $ordinal -eq 0 ]]; then\n
|
||||||
|
cp /mnt/config-map/master.cnf /mnt/conf.d/\n
|
||||||
|
else\n
|
||||||
|
cp /mnt/config-map/slave.cnf /mnt/conf.d/\n
|
||||||
|
fi\n
|
||||||
"],
|
"],
|
||||||
"volumeMounts": [
|
"volumeMounts": [
|
||||||
{"name": "data", "mountPath": "/mnt/data"},
|
{"name": "data", "mountPath": "/mnt/data"},
|
||||||
@@ -102,7 +107,7 @@ spec:
|
|||||||
# because we're cloning from an existing slave.
|
# because we're cloning from an existing slave.
|
||||||
mv xtrabackup_slave_info change_master_to.sql.in
|
mv xtrabackup_slave_info change_master_to.sql.in
|
||||||
# Ignore xtrabackup_binlog_info in this case (it's useless).
|
# Ignore xtrabackup_binlog_info in this case (it's useless).
|
||||||
rm xtrabackup_binlog_info
|
rm -f xtrabackup_binlog_info
|
||||||
elif [[ -f xtrabackup_binlog_info ]]; then
|
elif [[ -f xtrabackup_binlog_info ]]; then
|
||||||
# We're cloning directly from master. Parse binlog position.
|
# We're cloning directly from master. Parse binlog position.
|
||||||
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
|
[[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user