Skip to content

多集群管理全景

为什么需要多集群

  • 高可用:跨区域/跨云部署,避免单点故障
  • 隔离:生产/预发/开发环境隔离
  • 合规:数据主权,不同地区使用不同集群
  • 规模:单集群节点数限制(推荐 < 5000 节点)
  • 多云:避免云厂商锁定

多集群架构模式

模式一:独立集群(Federation)
  集群 A ←→ 集群 B ←→ 集群 C
  各自独立,通过联邦层统一管理

模式二:Hub-Spoke
  管理集群(Hub)
      ├── 工作集群 1(Spoke)
      ├── 工作集群 2(Spoke)
      └── 工作集群 3(Spoke)

模式三:服务网格联邦
  Istio 多集群,跨集群服务发现和流量管理

Karmada

bash
# 安装 Karmada
kubectl karmada-operator init --kubeconfig ~/.kube/config

# 注册成员集群
kubectl karmada join cluster1 --kubeconfig ~/.kube/config \
  --cluster-kubeconfig ~/.kube/cluster1.config

# 查看集群
kubectl get clusters
yaml
# 跨集群部署
apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: my-app-policy
spec:
  resourceSelectors:
  - apiVersion: apps/v1
    kind: Deployment
    name: my-app
  placement:
    clusterAffinity:
      clusterNames:
      - cluster1
      - cluster2
    replicaScheduling:
      replicaSchedulingType: Divided
      replicaDivisionPreference: Weighted
      weightPreference:
        staticClusterWeight:
        - targetCluster:
            clusterNames: [cluster1]
          weight: 2
        - targetCluster:
            clusterNames: [cluster2]
          weight: 1

Cluster API

bash
# 安装 clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.6.0/clusterctl-linux-amd64 -o clusterctl
chmod +x clusterctl && mv clusterctl /usr/local/bin/

# 初始化(以 AWS 为例)
export AWS_REGION=us-east-1
clusterctl init --infrastructure aws

# 创建集群
clusterctl generate cluster my-cluster \
  --kubernetes-version v1.29.0 \
  --control-plane-machine-count=3 \
  --worker-machine-count=3 | kubectl apply -f -

# 获取 kubeconfig
clusterctl get kubeconfig my-cluster > my-cluster.kubeconfig

多集群服务发现

yaml
# Submariner:跨集群 Service 发现
# 在集群 A 导出 Service
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ServiceExport
metadata:
  name: my-service
  namespace: production

# 在集群 B 导入 Service
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ServiceImport
metadata:
  name: my-service
  namespace: production
spec:
  type: ClusterSetIP
  ports:
  - port: 80
    protocol: TCP

本站内容由 褚成志 整理编写,仅供学习参考