在Kubernetes上安装MySQL-PXC集群
官方部署文档地址: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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2020-11-18 CentOS7 通过snat进行上网