升级适用于 Azure Service Fabric 的 Linux OS

本文档介绍如何将适用于 Linux 的 Azure Service Fabric 群集从 Ubuntu 版本 18.04 LTS 迁移到 20.04 LTS 的知识。 每个操作系统 (OS) 版本都需要不同的 Service Fabric 运行时包。 本文介绍简化迁移到较新版本所需的步骤。

备注

U18.04 已于 2023 年 6 月终止生命周期。 从 10.0CU1 版本开始,Service Fabric 运行时将停止对 U18.04 的支持。 Service Fabric 届时将不再提供更新或修补程序。

迁移方法

迁移的一般方法遵循以下步骤:

  1. 将 Service Fabric 群集 Azure 资源管理器资源 vmImage 切换到 Ubuntu20_04。 此设置将拉取此 OS 版本的未来代码升级。 OS 与现有节点类型的这种暂时不匹配情况会导致无法通过自动代码升级部署来确保安全滚动更新。

    提示

    避免在 OS 迁移期间发出手动 Service Fabric 群集代码升级。 这样做可能导致旧类型的节点进入需要人工干预的状态。

  2. 对于群集中的每个节点类型,为基础虚拟机规模集创建另一个以 Ubuntu 20.04 OS 映像为目标的节点类型。 每个新节点类型将充当其对应旧节点类型的角色。

    • 必须创建一个新的主节点类型来替换标记为 isPrimary: true 的旧节点类型。
    • 对于每个非初始代码类型,这些节点类型将标记为 isPrimary: false
    • 确保在创建新的目标 OS 节点类型后,现有工作负载可继续正常运行。 如果发现了问题,请在继续删除旧节点类型之前解决应用或预装的计算机包中所需的更改。
  3. 将旧的主节点类型标记为 isPrimary: false。 此设置会导致通过一组长时间运行的升级来转换所有种子节点。

  4. (仅适用于青铜级持久性节点类型):使用 sfctlPowerShellFabricClient 连接到群集。 禁用旧节点类型中的所有节点。

  5. 删除旧节点类型。

Az PowerShell 为添加的节点类型生成新的 DNS 名称。 将外部流量重定向到此终结点。

适用于非生产群集的易用步骤

此过程演示如何在仅限测试的群集中使用 Az PowerShell cmdlet 快速生成节点类型迁移的原型。 对于面向实际业务流量的生产群集,应通过发出资源管理器升级来完成相同的步骤,以保持可重放性和一致的声明性事实来源。

  1. 使用 Update-AzServiceFabricVmImage 更新 Service Fabric 群集资源上的 vmImage 设置:

    # Replace subscriptionId, resourceGroup, clusterName with ones corresponding to your cluster.
    $subscriptionId="cea219db-0593-4b27-8bfa-a703332bf433"
    Connect-AzAccount -Environment AzureChinaCloud; Select-AzSubscription -SubscriptionId $subscriptionId
    
    $resourceGroup="Group1"
    $clusterName="Contoso01SFCluster"
    # Update cluster vmImage to target OS. This registers the SF runtime package type that is supplied for upgrades.
    Update-AzServiceFabricVmImage -ResourceGroupName $resourceGroup -ClusterName $clusterName -VmImage Ubuntu20_04
    
  2. 为每个现有节点类型添加新的节点类型对应项:

    $nodeTypeName="nt1u18"
    # You can customize this to fetch a password from a secure store.
    $securePassword = ConvertTo-SecureString -String 'Yourpassword123!@#' -AsPlainText -Force
    
    # Ensure last upgrade is done - Ready means the next command can be issued.
    (Get-AzServiceFabricCluster -ResourceGroupName $resourceGroup).ClusterState
    
    # Add new primary node type. Omit the IsPrimaryNodeType parameter for non-primary node types.
    Add-AzServiceFabricNodeType -ResourceGroupName $resourceGroup  -ClusterName $clusterName -NodeType $nodeTypeName -Capacity 5 -VmUserName testuser -VmPassword $securePassword -DurabilityLevel Silver -Verbose -VMImageSku 18.04-LTS -IsPrimaryNodeType $true
    
    # Redirect traffic to new node type dns
    # dns-Contoso01SFCluster-nt1u18.chinanorth2.cloudapp.chinacloudapi.cn
    
  3. 将旧的主节点类型更新为非主节点类型,以便将种子节点和系统服务滚动更新为新节点类型:

    # Query to ensure background upgrades are done.
    (Get-AzServiceFabricCluster -ResourceGroupName $resourceGroup).ClusterState
    
    # Update old nodetype to isPrimary: false
    $oldNodeTypeName="nt1"
    Update-AzServiceFabricNodeType -ResourceGroupName $resourceGroup -ClusterName $clusterName -IsPrimaryNodeType $false -NodeType $oldNodeTypeName -Verbose
    
    # Ensure node type is showing isPrimary: False before proceeding.
    Get-AzServiceFabricCluster -ResourceGroupName $resourceGroup
    

    输出应类似于此输出:

    NodeTypes :
              NodeTypeDescription :
                  Name : nt1
                  PlacementProperties :
                  Capacities :
                  ClientConnectionEndpointPort : 19000
                  HttpGatewayEndpointPort : 19080
                  DurabilityLevel : Bronze
                  ApplicationPorts :
                      StartPort : 20000
                      EndPort : 30000
                  EphemeralPorts :
                      StartPort : 49152
                      EndPort : 65534
                  IsPrimary : False
                  VmInstanceCount : 5
                  ReverseProxyEndpointPort :
              NodeTypeDescription :
                  Name : nt1u18
                  PlacementProperties :
                  Capacities :
                  ClientConnectionEndpointPort : 19000
                  HttpGatewayEndpointPort : 19080
                  DurabilityLevel : Silver
                  ApplicationPorts :
                      StartPort : 20000
                      EndPort : 30000
                  EphemeralPorts :
                      StartPort : 49152
                      EndPort : 65534
                  IsPrimary : True
                  VmInstanceCount : 5
                  ReverseProxyEndpointPort :
    
  4. 若要删除铜级持久性节点类型,请先禁用节点,然后继续删除旧节点类型。 使用 ssh 连接到群集节点。 运行以下命令:

    # as root user:
    
    # install jq tool to automatically parse JSON responses
    apt-get install jq -fy
    
    # retrieve the thumbprint to be used for establishing a fabric client
    dataroot=$(cat /etc/servicefabric/FabricDataRoot)
    nodename=_nt1_0
    cat $dataroot/$nodename/Fabric/ClusterManifest.current.xml | grep ClientCertThumbprints
    # 0777FE1A43E306F332D96DA339EF6834D0E4A453
    
    # verify node count
    sfctl cluster select --endpoint https://Contoso01SFCluster.chinanorth2.cloudapp.chinacloudapi.cn:19080 --pem /var/lib/waagent/0777FE1A43E306F332D96DA339EF6834D0E4A453.pem --no-verify
    
    # sample command to list all nodes
    sfctl node list
    
    # for each node part of the node type to be removed, disable the node:
    nodeTypeBeingDisabled=nt1
    nodes=$(sfctl node list | jq --arg nodeTypeBeingDisabled "$nodeTypeBeingDisabled" '.items[] | select(.type==$nodeTypeBeingDisabled) | .name' | sed s/\"//g)
    echo $nodes
    for n in $nodes; do echo "Disabling $n"; sfctl node disable --node-name $n --deactivation-intent RemoveNode --timeout 300; done
    
  5. 通过删除 Service Fabric 群集资源节点类型属性并解除分配关联的虚拟机规模集和网络资源,来删除旧节点类型:

    $resourceGroup="Group1"
    $clusterName="Contoso01SFCluster"
    $oldNodeTypeName="nt1"
    
    # Remove the Service Fabric node type, associated virtual machine scale set resource, and any trailing networking resources that are no longer used. 
    Remove-AzServiceFabricNodeType -ResourceGroupName $resourceGroup -ClusterName $clusterName -NodeType $oldNodeTypeName
    

    备注

    在某些情况下,此命令可能会遇到以下错误:

    Remove-AzServiceFabricNodeType : Code: ClusterUpgradeFailed, Message: Long running operation failed with status 'Failed'
    

    使用 Service Fabric Explorer (SFX) 可能会发现,已删除节点类型的 InfrastructureService 处于错误状态。 重试删除。

确认已成功将工作负载迁移到新节点类型并且已清除旧节点类型。 然后,群集可以继续执行 Service Fabric 运行时代码版本和配置升级。

后续步骤