helm repo add bitnami https://charts.bitnami.com/bitnami
helm install mysql bitnami/mysql \
--set auth.rootPassword=123qwe \
--set architecture=replication \
--set secondary.replicaCount=1 \
--set secondary.persistence.storageClass=rook-ceph-block \
--set secondary.persistence.size=1G \
--set primary.persistence.storageClass=rook-ceph-block \
--set primary.persistence.size=1G
主库
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 339 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
从库
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: mysql-primary
Master_User: replicator
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 339
Relay_Log_File: mysql-relay-bin.000006
Relay_Log_Pos: 555
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
扩容从库
# kubectl get pods | grep mysql-secondary
mysql-secondary-0 1/1 Running 0 13h
mysql-secondary-1 1/1 Running 0 4m15s
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| bbc |
| information_schema |
| my_database |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: mysql-primary
Master_User: replicator
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 339
Relay_Log_File: mysql-relay-bin.000006
Relay_Log_Pos: 555
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
一主两从
# kubectl get pods | grep mysql
mysql-primary-0 1/1 Running 0 13h
mysql-secondary-0 1/1 Running 0 13h
mysql-secondary-1 1/1 Running 0 6m42s
更多参数
https://github.com/bitnami/charts/tree/master/bitnami/mysql/#parameters