global 集群灾难恢复

概述

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

该灾难恢复机制基于主集群到备用集群的 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 控制台,并切换到管理员视图;

  3. 导航到 Marketplace > Cluster Plugins,选择 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

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

上架软件包

WARNING

使用 violet 向备用集群上传软件包时,必须指定参数 --dest-repo <VIP addr of standby cluster>
否则,软件包将上传到主集群的镜像仓库,从而导致备用集群无法安装或升级扩展。

另请注意,必须提供备用集群镜像仓库的认证信息或 --no-auth 参数。

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