在Kubernetes上安裝MySQL-PXC叢集
阿新 • • 發佈:2021-11-18
官方部署文件地址:https://www.percona.com/doc/kubernetes-operator-for-pxc/kubernetes.html
一、部署方式
示例在k8s叢集(至少3個節點)中部署Percona XtraDB Cluster叢集
- clone專案
git clone https://gitee.com/Aaron-23/percona-xtradb-cluster-operator.git
cd percona-xtradb-cluster-operator
- 準備儲存
當前環境具有三個k8s node節點,每個node節點/var/lib/data目錄有100GB儲存空間
所有儲存均使用本地儲存
建立local-storageclass
cd storage
kubectl create -f local-sc.yaml
建立pv
修改values值為各pxc節點ip,spec.local.path
路徑根據實際情況自定義,
kubectl create -f pv-data-172.yaml
kubectl create -f pv-data-173.yaml
kubectl create -f pv-data-174.yaml
- 建立crd資源
kubectl apply -f deploy/crd.yaml
- 建立ns
kubectl create namespace pxc kubectl config set-context $(kubectl config current-context) --namespace=pxc
- 賦予rbac許可權
kubectl apply -f deploy/rbac.yaml
- 在Kubernetes中啟動operator
kubectl apply -f deploy/operator.yaml
- 使用secrets.管理Percona XtraDB叢集相關祕鑰
需要設定資料庫密碼的修改secrets
中密碼即可
kubectl create -f deploy/secrets.yaml
- 建立Percona XtraDB Cluster
kubectl apply -f deploy/cr.yaml
建立過程將花費一些時間。當po和副本數都達到“Running”狀態時,該過程結束:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
cluster1-haproxy-0 1/1 Running 0 5m
cluster1-haproxy-1 1/1 Running 0 5m
cluster1-haproxy-2 1/1 Running 0 5m
cluster1-pxc-0 1/1 Running 0 5m
cluster1-pxc-1 1/1 Running 0 4m
cluster1-pxc-2 1/1 Running 0 2m
percona-xtradb-cluster-operator-dc67778fd-qtspz 1/1 Running 0 6m
- 檢查與新建立叢集的連線
$ kubectl run -i --rm --tty percona-client --image=percona:8.0 --restart=Never -- bash -il
percona-client:/$ mysql -h cluster1-haproxy -uroot -proot_password
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1976
Server version: 8.0.19-10 Percona XtraDB Cluster (GPL), Release rel10, Revision 727f180, WSREP version 26.4.3
Copyright (c) 2009-2020 Percona LLC and/or its affiliates
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.