global 集群灾难恢复

概述

本方案面向 global 集群的灾难恢复场景而设计。global 集群作为平台的控制平面,负责管理其他集群。为确保在 global 集群发生故障时平台服务持续可用,本方案部署两个 global 集群:主集群和备用集群。

灾难恢复机制基于将主集群的 etcd 数据实时同步到备用集群。如果主集群因故障不可用,服务可快速切换到备用集群。

支持的灾难场景

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

不支持的灾难场景

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

主集群备用集群 的角色是相对的:当前为平台提供服务的集群是主集群(DNS 指向它),而待机集群是备用集群。发生故障切换后,这两个角色会互换。

注意事项

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

  • 为便于排障和管理,建议按 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(灾难恢复环境)安装注意事项

在安装 DR 环境的主集群时,

  • 首先,请记录按照安装 Web UI 指引过程中设置的所有参数;在安装备用集群时,需要保持其中部分选项一致。
  • 必须预先配置 User-provisioned Load Balancer,将流量转发到虚拟 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. 以与主集群相同的方式安装备用集群

备用集群安装注意事项

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

  • 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,并切换到 Administrator 视图;

  3. 进入 Marketplace > 集群插件,选择 global 集群;

  4. 找到 etcd Synchronizer,单击 Install,并配置参数:

    • 如果未通过负载均衡器转发端口 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 对象——包括 immutable-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 子命令的详细信息,请参阅 上架软件包