MySQL Operator 第二篇

简介:

  Operator让部署高可用集群非常简单,但是官方的Opeartor示例太少了,更新也太慢,就是一个玩具。这里主要是想借鉴一下官方思路,看看他们说如何做的。

GitHub链接:

https://github.com/mysql/mysql-operator
  •  部署MySQL Operator
  •  新建MySQL InnoDB Cluster集群
  •  测试连接

 

一、部署Operator kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-crds.yaml kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-operator.yaml     # 查看 kubectl get pods -n mysql-operator   二、部署InnoDB Cluster   1、secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: mypwds
stringData:
  rootUser: root
  rootHost: '%'
  rootPassword: "22QbCw6ZxXo5Bul7"

  

  2、sample-cluster.yaml
apiVersion: mysql.oracle.com/v2alpha1
kind: InnoDBCluster
metadata:
  name: mycluster
spec:
  secretName: mypwds
  instances: 3
  router:
    instances: 2

  



3、手动创建PV(创建三个PV,metadata.name不同就行)

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume-0
  labels:
    type: local
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/mycluster"

  

 

# 注意: 官方示例中没有创建PV的提示,但是这步是必须的,一般这里是最容易出错的,最好查看下PV状态,看看有没有绑定

# kubectl get pvc
NAME                  STATUS   VOLUME              CAPACITY   ACCESS MODES   STORAGECLASS   AGE
datadir-mycluster-0   Bound    mysql-pv-volume-0   2Gi        RWO                           23h
datadir-mycluster-1   Bound    mysql-pv-volume-1   2Gi        RWO                           23h
datadir-mycluster-2   Bound    mysql-pv-volume-2   2Gi        RWO                           23h

  

 

 

 

三、访问测试

# 查看service ip
kubectl get service mycluster

mysql -h10.106.187.34 -P6446 -uroot -p

  

 # 查看MGR集群成员状态

mysql> SELECT MEMBER_HOST,MEMBER_STATE,MEMBER_ROLE,MEMBER_VERSION FROM performance_schema.replication_group_members;
+-----------------------------------------------------------+--------------+-------------+----------------+
| MEMBER_HOST | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+-----------------------------------------------------------+--------------+-------------+----------------+
| mycluster-1.mycluster-instances.default.svc.cluster.local | ONLINE | SECONDARY | 8.0.25 |
| mycluster-2.mycluster-instances.default.svc.cluster.local | ONLINE | SECONDARY | 8.0.25 |
| mycluster-0.mycluster-instances.default.svc.cluster.local | ONLINE | PRIMARY | 8.0.25 |
+-----------------------------------------------------------+--------------+-------------+----------------+
3 rows in set (0.00 sec)

  

 

 

 

 

 

 

上一篇:openstack 虚机热迁移问题:虚机状态一直处于迁移中的情况处理


下一篇:CESIUM-大量model加载(ModelInstanceCollection)