global 集群容灾

概述

本方案面向 global 集群的容灾场景。global 集群作为平台的控制平面,负责管理其他集群。为确保在 global 集群发生故障时平台服务仍可持续可用,本方案部署两个 global 集群:主集群(Primary Cluster)和备集群(Standby Cluster)。

容灾机制基于将主集群的 etcd 数据实时同步至备集群。当主集群因故障不可用时,服务可快速切换至备集群。

支持的容灾场景

  • 主集群发生不可恢复的系统级故障,导致其无法运行;
  • 承载主集群的物理机或虚拟机发生故障,导致其无法访问;
  • 主集群所在位置发生网络故障,导致服务中断;

不支持的容灾场景

  • global 集群内部署的应用发生故障;
  • 存储系统故障导致的数据丢失(不在 etcd 同步范围内);

主集群备集群的角色是相对的:当前为平台提供服务的集群为主集群(DNS 指向该集群),另一集群为备集群。故障切换后,这两个角色将互换。

注意事项

  • 本方案仅同步 global 集群的 etcd 数据,不包括 registry、chartmuseum 或其他组件的数据;

  • 监控和日志数据也不会同步。请勿将业务集群的监控或日志数据存储在主集群或备集群中:将用于聚合业务集群数据的 VictoriaMetrics Center 和日志存储安装在专用的业务集群中,并让每个 global 集群仅采集、存储和查询自身的指标和日志。主集群中保存的可观测性数据在故障切换后将不可用,因此依赖这些数据的备集群将无法观测其刚刚接管的平台;

  • 为便于故障排查和管理,建议以类似 standby-global-m1 的风格命名节点,以表明该节点所属的集群(主集群或备集群)。

  • 不支持集群内应用数据的容灾;

  • 两个集群之间需要稳定的网络连通性,以确保 etcd 同步可靠进行;

  • 如果集群基于异构架构(例如 x86 和 ARM),请使用双架构安装包;

  • 以下命名空间不在 etcd 同步范围内。如果在这些命名空间中创建了资源,用户必须手动备份:

    cpaas-system
    cert-manager
    default
    global-credentials
    cpaas-system-global-credentials
    kube-ovn
    kube-public
    kube-system
    nsx-system
    cpaas-solution
    kube-node-lease
    kubevirt
    nativestor-system
    operators
  • 如果两个集群均设置为使用内置镜像仓库,则必须分别向每个集群上传容器镜像;

  • 如果主集群部署了 DevOps Eventing v3(knative-operator)及其实例,则必须在备集群中预先部署相同的组件。

流程概览

  1. 准备用于平台访问的统一域名;
  2. 将域名指向主集群的 VIP,并安装主集群
  3. 临时将 DNS 解析切换至备集群 VIP,以安装备集群;
  4. 主集群的 ETCD 加密密钥复制到后续将作为备集群控制平面节点的节点上;
  5. 安装并启用 etcd 同步插件;
  6. 验证同步状态并执行定期检查;
  7. 发生故障时,将 DNS 切换至备集群以完成容灾。

所需资源

  • 一个统一域名,将作为 Platform Access Address,以及用于在该域名上提供 HTTPS 服务的 TLS 证书和私钥;

  • 每个集群各需一个专用虚拟 IP 地址——一个用于主集群,另一个用于备集群;

    • 预先配置负载均衡器,将端口 804436443237911443 上的 TCP 流量路由到对应 VIP 后面的控制平面节点。

操作步骤

步骤 1:安装主集群

容灾(DR)环境安装注意事项

在安装容灾环境的主集群时,

  • 首先,请记录按照安装 Web UI 指南设置的所有参数。安装备集群时,部分选项必须保持一致。
  • 必须预先配置 User-Provisioned 负载均衡器,以将发送到虚拟 IP 的流量进行路由。Self-built VIP 选项不可用。
  • Platform Access Address 字段必须为域名,而 Cluster Endpoint 必须为虚拟 IP 地址。
  • 两个集群都必须配置为使用 An Existing Certificate(必须为同一证书),如有必要请申请合法证书。Self-signed Certificate 选项不可用。
  • Image Repository 设置为 Platform Deployment 时,UsernamePassword 字段均不得为空;IP/Domain 字段必须设置为用作 Platform Access Address 的域名。
  • Platform Access AddressHTTP PortHTTPS Port 字段必须分别为 80 和 443。
  • 进入安装指南的第二页(步骤:Advanced)时,Other Platform Access Addresses 字段必须包含当前集群的虚拟 IP。

请参阅以下文档完成安装:

步骤 2:安装备集群

  1. 临时将域名指向备集群的 VIP;

  2. 登录主集群的第一个控制平面节点,并将 etcd 加密配置复制到备集群的所有控制平面节点:

    # Assume the primary cluster control plane nodes are 1.1.1.1, 2.2.2.2 & 3.3.3.3
    # and the standby cluster control plane nodes are 4.4.4.4, 5.5.5.5 & 6.6.6.6
    for i in 4.4.4.4 5.5.5.5 6.6.6.6  # Replace with standby cluster control plane node IPs
    do
      ssh "<user>@$i" "sudo mkdir -p /etc/kubernetes/"
      scp /etc/kubernetes/encryption-provider.conf "<user>@$i:/tmp/encryption-provider.conf"
      ssh "<user>@$i" "sudo install -o root -g root -m 600 /tmp/encryption-provider.conf /etc/kubernetes/encryption-provider.conf && rm -f /tmp/encryption-provider.conf"
    done
  3. 以与主集群相同的方式安装备集群

备集群安装注意事项

在安装容灾环境的备集群时, 以下选项必须与主集群保持一致:

  • Platform Access Address 字段。
  • Certificate 的所有字段。
  • Image Repository 的所有字段
  • 重要:确保镜像仓库的凭据以及 管理员用户与主集群上设置的一致。

并确保已遵循步骤 1 中的「容灾(DR)环境安装注意事项」。

请参阅以下文档完成安装:

步骤 3:启用 etcd 同步

  1. 在适用的情况下,配置负载均衡器将端口 2379 转发到对应集群的控制平面节点。仅支持 TCP 模式,不支持 L7 转发。

    INFO

    无需通过负载均衡器进行端口转发。 如果备集群可直接访问当前活动的 global 集群,请通过 Active Global Cluster ETCD Endpoints 指定 etcd 地址。

  2. 使用其 VIP 访问备 global 集群的 Web Console,并切换到管理员视图;

  3. 导航至 Marketplace > 集群插件,选择 global 集群;

  4. 找到 etcd Synchronizer,单击安装,配置参数:

    • 未通过负载均衡器转发端口 2379 时,必须正确配置 Active Global Cluster ETCD Endpoints
    • Data Check Interval 使用默认值;
    • 除非进行故障排查,否则请将 Print detail logs 开关保持关闭。

验证备集群上的同步 Pod 正在运行:

kubectl get po -n cpaas-system -l app=etcd-sync
kubectl logs -n cpaas-system $(kubectl get po -n cpaas-system -l app=etcd-sync --no-headers | head -1) | grep -i "Start Sync update"

一旦出现 “Start Sync update”,请重建其中一个 Pod,以重新触发具有 ownerReference 依赖关系的资源同步:

kubectl delete po -n cpaas-system $(kubectl get po -n cpaas-system -l app=etcd-sync --no-headers | head -1)

检查同步状态:

mirror_svc=$(kubectl get svc -n cpaas-system etcd-sync-monitor -o jsonpath='{.spec.clusterIP}')
ipv6_regex="^[0-9a-fA-F:]+$"
if [[ $mirror_svc =~ $ipv6_regex ]]; then
  export mirror_new_svc="[$mirror_svc]"
else
  export mirror_new_svc=$mirror_svc
fi
curl $mirror_new_svc/check

输出说明:

  • LOCAL ETCD missed keys:主集群中存在但备集群中缺失的键。通常由同步过程中因资源顺序触发的 GC 导致。重启一个 etcd-sync Pod 即可修复;
  • LOCAL ETCD surplus keys:仅存在于备集群中的多余键。在从备集群删除这些键之前,请与运维团队确认。

如果已安装以下组件,请重启其服务:

  • Log Storage for Elasticsearch:

    kubectl delete po -n cpaas-system -l service_name=cpaas-elasticsearch
  • Monitoring for VictoriaMetrics:

    kubectl delete po -n cpaas-system -l 'service_name in (alertmanager,vmselect,vminsert)'

容灾流程

卸载 etcd 同步插件前请验证主备一致性

此操作步骤将卸载 etcd 同步插件。卸载前,请确认备集群数据与主集群一致。如果在备集群缺失主集群所持数据的情况下卸载该插件,可能导致 owner references 解析不正确,并且业务集群节点的 Machine 对象可能会被删除——对于不可变 OS 集群,这会销毁其底层虚拟机。如果一致性检查报告存在缺失或多余的键,请勿卸载该插件;请先解决不一致问题或联系技术支持。

  1. 如有必要,在备集群上重启 Elasticsearch:

    # Copy installer/res/packaged-scripts/for-upgrade/ensure-asm-template.sh to /root:
    # DO NOT skip this step
    
    # switch to the root user if necessary
    sudo -i
    
    # check whether the Log Storage for Elasticsearch is installed on global cluster
    _es_pods=$(kubectl get po -n cpaas-system | grep cpaas-elasticsearch | awk '{print $1}')
    if [[ -n "${_es_pods}" ]]; then
        # In case the script returned the 401 error, restart Elasticsearch
        # then execute the script to check the cluster again
        bash /root/ensure-asm-template.sh
    
        # Restart Elasticsearch
        xargs -r -t -- kubectl delete po -n cpaas-system <<< "${_es_pods}"
    fi
  2. 验证备集群中的数据一致性(与 步骤 3 中的检查相同)。如果检查报告存在缺失或多余的键,则备集群与主集群不一致:请勿继续下一步。请先解决不一致问题或联系技术支持。同时在两个集群上确认没有处于非运行状态的 Machine 节点,并在继续之前解决所有此类问题:

    kubectl get machines.platform.tkestack.io
  3. 卸载 etcd 同步插件;

  4. 从两个 VIP 上移除 2379 的端口转发;

  5. 将平台域名的 DNS 切换至备集群 VIP,该集群现在成为主集群;

  6. 验证 DNS 解析:

    kubectl exec -it -n cpaas-system deployments/sentry -- nslookup <platform access domain>
    # If not resolved correctly, restart coredns Pods and retry until success
  7. 清除浏览器缓存并访问平台页面,确认其展示的是原备集群;

  8. 重启以下服务(如已安装):

    • Log Storage for Elasticsearch:

      kubectl delete po -n cpaas-system -l service_name=cpaas-elasticsearch
    • Monitoring for VictoriaMetrics:

      kubectl delete po -n cpaas-system -l 'service_name in (alertmanager,vmselect,vminsert)'
    • cluster-transformer:

      kubectl delete po -n cpaas-system -l service_name=cluster-transformer
  9. 如果业务集群将监控数据发送到主集群,请在业务集群中重启 warlock:

    kubectl delete po -n cpaas-system -l service_name=warlock
  10. 在原主集群上,重复 启用 etcd 同步 的步骤,将其转换为新的备集群。

日常检查

定期在备集群上检查同步状态:

curl $(kubectl get svc -n cpaas-system etcd-sync-monitor -o jsonpath='{.spec.clusterIP}')/check

如果存在任何缺失或多余的键,请按照输出中的说明进行解决。

上架软件包

有关 violet push 子命令的详细信息,请参阅 上架软件包