1. 程式人生 > >kubernetes生產實踐之mysql

kubernetes生產實踐之mysql

### 簡介 kubedb mysql 生命週期及特性 ![](https://img2020.cnblogs.com/blog/2156744/202103/2156744-20210311114056822-1640034844.png) ``` Supported MySQL Features Features Availability Clustering ✓ Persistent Volume ✓ Instant Backup ✓ Scheduled Backup ✓ Initialize using Snapshot ✓ Initialize using Script (*.sql, *sql.gz and/or *.sh) ✓ Custom Configuration ✓ Using Custom docker image ✓ Builtin Prometheus Discovery ✓ Using Prometheus operator ✓ ``` ### 檢視kubedb支援的mysql版本 ``` [root@qd01-stop-k8s-master001 mysql]# kubectl get mysqlversions NAME VERSION DB_IMAGE DEPRECATED AGE 5.7.25-v1 5.7.25 kubedb/mysql:5.7.25-v1 17h 5.7.29 5.7.29 kubedb/mysql:5.7.29 17h 5.7.31 5.7.31 kubedb/mysql:5.7.31 17h 8.0.14-v1 8.0.14 kubedb/mysql:8.0.14-v1 17h 8.0.20 8.0.20 kubedb/mysql:8.0.20 17h 8.0.21 8.0.21 kubedb/mysql:8.0.21 17h 8.0.3-v1 8.0.3 kubedb/mysql:8.0.3-v1 17h ``` ### 編寫配置檔案 mode: GroupReplication ![](https://img2020.cnblogs.com/blog/2156744/202103/2156744-20210311114115204-1601854267.png) group.name可以使用這個網站生成:https://www.uuidgenerator.net/version4 ``` apiVersion: kubedb.com/v1alpha2 kind: MySQL metadata: name: mysql-group-test namespace: op spec: version: "8.0.21" replicas: 3 topology: mode: GroupReplication group: name: "d7f38430-d9ee-464b-af43-da9efa26fe02" baseServerID: 100 storageType: Durable storage: storageClassName: "rbd" accessModes: - ReadWriteOnce resources: requests: storage: 50Gi terminationPolicy: Halt ``` ### 安裝Mysql ``` [root@qd01-stop-k8s-master001 mysql]# kubectl apply -f mysql-cluster-install.yaml mysql.kubedb.com/mysql-group-test created [root@qd01-stop-k8s-master001 mysql]# kubectl get po,ep,svc -n op NAME READY STATUS RESTARTS AGE pod/mysql-group-test-0 2/2 Running 0 14m pod/mysql-group-test-1 2/2 Running 0 9m41s pod/mysql-group-test-2 2/2 Running 0 4m19s NAME ENDPOINTS AGE endpoints/mysql-group-test 100.64.147.157:3306 14m endpoints/mysql-group-test-pods 100.64.122.198:3306,100.64.147.157:3306,100.98.174.219:3306 14m endpoints/mysql-group-test-standby 100.98.174.219:3306 14m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/mysql-group-test ClusterIP 10.108.25.179