云原生设计

Kubernetes Operator

Mycat3 Operator 负责在Kubernetes中自动化管理Mycat3集群的整个生命周期。

apiVersion: Mycat3.io/v1
kind: Mycat3Cluster
metadata:
  name: my-production
  namespace: Mycat3
spec:
  version: 3.0.0
  replicas: 3
  image: Mycat3/Mycat3:3.0.0
  resources:
    requests:
      cpu: 2
      memory: 4Gi
    limits:
      cpu: 4
      memory: 8Gi
  storage:
    persistenceEnabled: true
    size: 100Gi
    storageClass: ssd
  autoscaling:
    enabled: true
    minReplicas: 2
    maxReplicas: 10
    targetCPUUtilization: 80
  service:
    type: ClusterIP
    ports:
      - name: mysql
        port: 3306
        targetPort: 3306
      - name: admin
        port: 9066
        targetPort: 9066
      - name: metrics
        port: 9090
        targetPort: 9090

Helm部署

# 添加仓库
helm repo add Mycat3 https://charts.Mycat3.io

# 安装
helm install my-Mycat3 Mycat3/Mycat3 \
  --set cluster.replicas=3 \
  --set storage.type=mysql \
  --set ai.enabled=true \
  --namespace Mycat3 \
  --create-namespace

# 查看状态
helm status my-Mycat3 -n Mycat3

# 升级
helm upgrade my-Mycat3 Mycat3/Mycat3 \
  --set image.tag=3.1.0 \
  -n Mycat3

自动弹性伸缩

水平伸缩 (HPA)

autoscaling:
  enabled: true
  horizontal:
    minReplicas: 3
    maxReplicas: 20
    metrics:
      - type: Resource
        resource:
          name: cpu
          targetAverageUtilization: 70
      - type: Pods
        pods:
          metricName: Mycat3_connections_active
          targetAverageValue: 500
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
    scaleUp:
      stabilizationWindowSeconds: 60

垂直伸缩 (VPA)

verticalAutoscaling:
  enabled: true
  updateMode: Auto
  minAllowed:
    cpu: 1
    memory: 2Gi
  maxAllowed:
    cpu: 8
    memory: 32Gi

服务网格集成

支持与Istio/Linkerd集成,实现:

  • 流量管理: 金丝雀发布、蓝绿部署、流量镜像
  • 可观测性: 分布式追踪、指标收集、日志聚合
  • 安全性: mTLS、细粒度访问控制
# Istio VirtualService 示例
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: Mycat3-vs
spec:
  hosts:
    - Mycat3.Mycat3.svc.cluster.local
  http:
    - match:
        - headers:
            version:
              exact: v3.0
      route:
        - destination:
            host: Mycat3-v3.Mycat3.svc.cluster.local
            subset: stable
            port:
              number: 3306
          weight: 90
        - destination:
            host: Mycat3-v3.Mycat3.svc.cluster.local
            subset: canary
            port:
              number: 3306
          weight: 10

多租户设计

隔离级别说明
Namespace级每个租户独立K8s Namespace
集群级共享集群,通过Schema隔离
节点级通过NodeSelector独享计算节点
网络级通过NetworkPolicy实现网络隔离
multiTenancy:
  enabled: true
  mode: namespace           # namespace / schema / node
  tenants:
    - name: tenant-a
      namespace: Mycat3-tenant-a
      quota:
        cpu: 8
        memory: 32Gi
        storage: 500Gi
        maxConnections: 500
    - name: tenant-b
      namespace: Mycat3-tenant-b
      quota:
        cpu: 4
        memory: 16Gi
        storage: 200Gi
        maxConnections: 200
注意: 云原生特性为Mycat3.0的核心设计目标,将在Phase 2阶段全面实现。