K8S中部署MySQL高可用工具Orchestrator

Orchestrator 是一个用于管理和监控 MySQL 和 MariaDB 主从复制环境的开源工具。它提供了功能强大的主从复制拓扑可视化、故障转移(failover)和高可用性(HA)管理功能。

复制拓扑可视化

  • Orchestrator 提供图形化界面展示 MySQL 主从复制拓扑结构。你可以直观地看到主节点和从节点的关系,以及它们的状态信息。

故障转移与恢复

  • Orchestrator 支持自动故障转移功能。在主节点发生故障时,Orchestrator 可以自动将一个从节点提升为新的主节点,并更新复制拓扑结构。

主从结构检测

  • Orchestrator 定期扫描 MySQL 实例,检测主从结构的变化。它能够识别复制中的问题,如主节点或从节点的状态异常。

主节点选择

  • 在发生故障时,Orchestrator 可以根据配置自动选择最合适的从节点提升为主节点,确保最小化停机时间。

分片支持

  • Orchestrator 支持分片的 MySQL 环境,可以管理具有多个主节点的复制拓扑。

高可用性监控

  • 监控主从复制的健康状态,包括复制延迟、主从状态一致性等。

警告与通知

  • Orchestrator 可以配置警告和通知,以便在出现主从复制问题时及时通知管理员。

手动故障转移

  • 除了自动故障转移,Orchestrator 还支持手动故障转移操作,允许管理员在需要时手动介入。

Web 界面和 API

  • 提供了 Web 界面和 REST API 以便于管理和自动化操作。管理员可以通过 Web 界面进行操作,也可以通过 API 进行集成和脚本化管理

本次部署主要针对单节点情况,对orchestrator在k8s中部署的代码进行展示

第一 orchestrator后端数据库

创建命名空间

kubectl create namespace strator

部署 Orchestrator 后端数据库

编写一个 db-orchestrator.yaml 文件,内容如下

apiVersion: v1
kind: Service
metadata:
  name: orchestrator-db
  namespace: strator
spec:
  ports:
    - port: 3306
    selector:
    app: orchestrator-db
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: orchestrator-db
  namespace: strator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: orchestrator-db
  template:
    metadata:
      labels:
        app: orchestrator-db
    spec:
      containers:
        - name: mysql
          image: mysql:8.0
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: Tgqs@123
            - name: MYSQL_DATABASE
              value: orchestrator
            - name: MYSQL_USER
              value: orchestrator_user
            - name: MYSQL_PASSWORD
              value: Tgqs@123
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc
  namespace: strator
spec:
  accessModes:
    - ReadWriteOnce
    resources:
        requests:
      storage: 5Gi

创建该文件后,通过以下命令应用配置

kubectl apply -f db-orchestrator.yaml

第二 部署 orchestrator

使用 ConfigMap 来配置 Orchestrator,以便自动化检测和切换 MySQL 数据库的主从角色。

创建configmap

vim orchestrator-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: orchestrator-config
  namespace: strator
data:
  orchestrator.conf.json: |
{
  "Debug": true,
  "MySQLTopologyUser": "orche",
  "MySQLTopologyPassword": "Tgqs@123",
  "MySQLOrchestratorHost": "orchestrator-db",
  "MySQLOrchestratorPort": 3306,
  "MySQLOrchestratorUser": "orchestrator",
  "MySQLOrchestratorPassword": "Tgqs@123",
  "MySQLOrchestratorDatabase": "orchestrator",
  "HostnameResolveMethod": "default", 
  "MySQLHostnameResolveMethod": "@@hostname",
  "InstancePollSeconds": 60,
  "FailureDetectionPeriodBlockMinutes": 60,
  "RecoverMasterClusterFilters": ["*"],
  "RecoverIntermediateMasterClusterFilters": ["*"]
}

应用配置

kubectl apply -f orchestrator-configmap.yaml

创建deployment

vim orchestrator-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: orchestrator
  namespace: strator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: orchestrator
  template:
    metadata:
      labels:
        app: orchestrator
    spec:
      containers:
        - name: orchestrator
          image: openarkcode/orchestrator:latest
          ports:
            - containerPort: 3000
          volumeMounts:
            - name: orchestrator-config
              mountPath: /etc/orchestrator.conf.json
              subPath: orchestrator.conf.json
      volumes:
        - name: orchestrator-config
          configMap:
            name: orchestrator-config

应用配置

kubectl apply -f orchestrator-deployment.yaml

配置service
apiVersion: v1
kind: Service
metadata:
  name: orchestrator
  namespace: strator
spec:
  selector:
    app: orchestrator
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
      nodePort: 32300  # 手动指定 NodePort 端口
  type: NodePort

第三 验证

查看pod状态

kubectl get po -n strator
在这里插入图片描述

登录orchestrator的web界面

在这里插入图片描述

监控集群中的其他命名空间的mysql

查看 orche 命名空间中的 MySQL Services

kubectl get svc -n orche

NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
mysql-master     ClusterIP   10.100.200.1     <none>        3306/TCP   10m
mysql-slave      ClusterIP   10.100.200.2     <none>        3306/TCP   10m

登录orchestrator的web界面,选择 “Discover”

http://:32000

mysql-master.orche.svc.cluster.local:3306
mysql-slave.orche.svc.cluster.local:3306

注:

mysql-slave.orche.svc.cluster.local:3306 是 Kubernetes 内部的一个完整的服务地址(URL),这个地址在 Kubernetes 集群内部使用,允许 Pod、服务和其他 Kubernetes 资源通过 DNS 解析并访问这个 MySQL 从节点服务。

mysql-slave 是 Kubernetes 中定义的一个服务 (Service) 名称,表示暴露 MySQL 从节点的。

svc 可以理解为告诉 Kubernetes 这是一个服务

cluster.local 是 Kubernetes 集群的默认域名后缀。它表示这是集群内部的一个域名,通常不会从集群外部访问。

  • 16
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值