kubernetes生产实践之mysql (2)

1、获取root用户名密码

[root@qd01-stop-k8s-master001 mysql]# kubectl get secrets -n op mysql-group-test-auth -o jsonpath='{.data.\username}' | base64 -d root [root@qd01-stop-k8s-master001 mysql]# kubectl get secrets -n op mysql-group-test-auth -o jsonpath='{.data.\password}' | base64 -d 8(wVGGRfF4iQq1Zt

2、查看mysql pod 列表

[root@qd01-stop-k8s-master001 mysql]# kubectl get pods -n op -l app.kubernetes.io/instance=mysql-group-test -o jsonpath='{range.items[*]}{.metadata.name} ........... {.status.podIP} ............ {.metadata.name}.my-group-gvr.{.metadata.namespace}{"\t\n"}{end}' mysql-group-test-0 ........... 100.64.147.157 ............ mysql-group-test-0.my-group-gvr.op mysql-group-test-1 ........... 100.98.174.219 ............ mysql-group-test-1.my-group-gvr.op mysql-group-test-2 ........... 100.64.122.198 ............ mysql-group-test-2.my-group-gvr.op [root@qd01-stop-k8s-master001 mysql]# kubectl get svc -n op NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-group-test ClusterIP 10.108.25.179 <none> 3306/TCP 43m mysql-group-test-pods ClusterIP None <none> 3306/TCP 43m mysql-group-test-standby ClusterIP 10.101.164.49 <none> 3306/TCP 43m

3、现在可以使用获取到的信息连接数据库

[root@qd01-stop-k8s-master001 mysql]# kubectl exec -it -n op mysql-group-test-0 -c mysql -- mysql -u root --password="8(wVGGRfF4iQq1Zt" --host=10.108.25.179 -e "select 1;" mysql: [Warning] Using a password on the command line interface can be insecure. +---+ | 1 | +---+ | 1 | +---+

4、检查集群状态

[root@qd01-stop-k8s-master001 mysql]# kubectl exec -it -n op mysql-group-test-0 -c mysql -- mysql -u root --password="8(wVGGRfF4iQq1Zt" --host=10.108.25.179 -e "show status like '%primary%'" mysql: [Warning] Using a password on the command line interface can be insecure. +----------------------------------+--------------------------------------+ | Variable_name | Value | +----------------------------------+--------------------------------------+ | group_replication_primary_member | 596744e1-820e-11eb-8425-f2f48f05462c | +----------------------------------+--------------------------------------+ [root@qd01-stop-k8s-master001 mysql]# 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 | SECONDARY | 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 | PRIMARY | 8.0.21 | +---------------------------+--------------------------------------+---------------------------------------------+-------------+--------------+-------------+----------------+

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsfppz.html