5、故障测试
我现在把PRIMARY的mysql-group-test-0 pod删除,然后再查看集群信息,mysql-group-test-1会提升为PRIMARY
[root@qd01-stop-k8s-master001 ~]# kubectl delete po mysql-group-test-0 -n op
[root@qd01-stop-k8s-master001 ~]# kubectl exec -it -n op mysql-group-test-0 -n op -c mysql -- mysql -u root --password="8(wVGGRfF4iQq1Zt" --host=10.108.25.179 -e "select * from performance_schema.replication_group_members"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------------+--------------------------------------+---------------------------------------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME
| MEMBER_ID
| MEMBER_HOST
| MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+---------------------------------------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 18b45cbd-820f-11eb-8060-9a70fb141a1f | mysql-group-test-1.mysql-group-test-pods.op |
3306 | ONLINE
| PRIMARY
| 8.0.21
|
| group_replication_applier | 1dd5699c-8210-11eb-b13a-9a07d15a7e1f | mysql-group-test-2.mysql-group-test-pods.op |
3306 | ONLINE
| SECONDARY | 8.0.21
|
+---------------------------+--------------------------------------+---------------------------------------------+-------------+--------------+-------------+----------------+
等待一段时间 mysql-group-test-0起来以后,角色就变成SECONDARY
[root@qd01-stop-k8s-master001 ~]# kubectl exec -it -n op mysql-group-test-0 -c mysql -- mysql -u root --password="8(wVGGRfF4iQq1Zt" --host=10.108.25.179 -e "select * from performance_schema.replication_group_members"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------------+--------------------------------------+---------------------------------------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME
| MEMBER_ID
| MEMBER_HOST
| MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+---------------------------------------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 18b45cbd-820f-11eb-8060-9a70fb141a1f | mysql-group-test-1.mysql-group-test-pods.op |
3306 | ONLINE
| PRIMARY
| 8.0.21
|
| group_replication_applier | 1dd5699c-8210-11eb-b13a-9a07d15a7e1f | mysql-group-test-2.mysql-group-test-pods.op |
3306 | ONLINE
| SECONDARY | 8.0.21
|
| group_replication_applier | 596744e1-820e-11eb-8425-f2f48f05462c | mysql-group-test-0.mysql-group-test-pods.op |
3306 | ONLINE
| SECONDARY | 8.0.21
|
+---------------------------+--------------------------------------+---------------------------------------------+-------------+--------------+-------------+----------------+
注意:因为本文部署是使用的是GroupReplication模式(目前kubed只支持这种模式),只能从PRIMARY节点写入数据,所有节点都可以读取数据;如下图所示。
如果想使用集群模式,参见以前的