Share via


擴大 Service Fabric 叢集非主要節點類型

此文章說明如何以最短的停機時間擴大 Service Fabric 叢集非主要節點類型。 Service Fabric 叢集節點上不支援就地 SKU 升級,因為此類作業可能會牽涉到資料和可用性遺失。 最安全、最可靠且建議的擴大 Service Fabric 節點類型方法為:

  1. 將新的節點類型新增到您的 Service Fabric 叢集,由您的已升級 (或已修改) 虛擬機器擴展集 SKU 和設定作為後盾。 此步驟也包含為擴展集設定新的負載平衡器、子網路和公用 IP。

  2. 一旦原始和升級的擴展集同時執行之後,請將應用程式的放置條件約束設定為新的節點類型來移轉工作負載。

  3. 確認叢集的狀況良好,然後移除已刪除節點的原始擴展集 (和相關資源) 和節點狀態。

下列程序會逐步引導您使用具有銀級持久性 (由具有五個節點作為次要節點類型的單一擴展集所支援),更新範例叢集非主要節點類型 VM 的 VM 大小和作業系統。 Service Fabric 系統服務的主要節點類型會維持不變。 我們會升級非主要節點類型:

  • 從 VM 大小 Standard_D2_V2 升級為 Standard D4_V2,以及
  • 從 VM 作業系統 Windows Server 2019 DatacenterWindows Server 2022 Datacenter

警告

在對生產叢集嘗試此程序之前,建議您先研究範本範例,並確認要對測試叢集所進行的程序。

如果叢集狀態狀況不良,請不要嘗試使用非主要節點類型擴大程序,因為這只會進一步使叢集不穩定。 我們將使用擴大 Service Fabric 叢集主要節點類型指南中使用的逐步 Azure 部署範本。 不過,我們會加以修改,使其不會特定於主要節點類型。 範本可在 GitHub 上取得 (英文)。

設定測試叢集

讓我們設定初始 Service Fabric 測試叢集。 首先,請下載我們將會用來完成此案例的 Azure Resource Manager 範例範本。

接著,登入您的 Azure 帳戶。

# Sign in to your Azure account
Login-AzAccount -SubscriptionId "<subscription ID>"

接下來開啟 parameters.json 檔案並且將 clusterName 的值更新為唯一值 (在 Azure 內)。

下列命令會引導您產生新的自我簽署憑證,並部署測試叢集。 如果您已經有想要使用的憑證,請跳到使用現有的憑證來部署叢集

產生自我簽署憑證及部署叢集

首先,指派 Service Fabric 叢集部署所需的變數。 針對您的特定帳戶和環境,調整 resourceGroupNamecertSubjectNameparameterFilePathtemplateFilePath 的值:

# Assign deployment variables
$resourceGroupName = "sftestupgradegroup"
$certOutputFolder = "c:\certificates"
$certPassword = "Password!1" | ConvertTo-SecureString -AsPlainText -Force
$certSubjectName = "sftestupgrade.southcentralus.cloudapp.azure.com"
$parameterFilePath = "C:\parameters.json"
$templateFilePath = "C:\Initial-TestClusterSetup.json"

注意

執行命令之前,確保 certOutputFolder 位置存在於本機電腦上,以部署新的 Service Fabric 叢集。 然後部署 Service Fabric 測試叢集:

# Deploy the initial test cluster
New-AzServiceFabricCluster `
    -ResourceGroupName $resourceGroupName `
    -CertificateOutputFolder $certOutputFolder `
    -CertificatePassword $certPassword `
    -CertificateSubjectName $certSubjectName `
    -TemplateFile $templateFilePath `
    -ParameterFile $parameterFilePath

部署完成後,請在本機電腦上找出 .pfx 檔案 ($certPfx),並將其匯入到您的憑證存放區:

cd c:\certificates
$certPfx = ".\sftestupgradegroup20200312121003.pfx"
Import-PfxCertificate `
     -FilePath $certPfx `
     -CertStoreLocation Cert:\CurrentUser\My `
     -Password (ConvertTo-SecureString Password!1 -AsPlainText -Force)

此作業會傳回憑證指紋,您現在可以將其用來連線到新叢集並檢查其健全狀態。 (略過下一節,這是叢集部署的替代方法。)

使用現有的憑證來部署叢集

或者,您可以使用現有的 Azure Key Vault 憑證來部署測試叢集。 若要這樣做,您必須取得 Key Vault 的參考和憑證指紋。

# Key Vault variables
$certUrlValue = "https://sftestupgradegroup.vault.azure.net/secrets/sftestupgradegroup20200309235308/dac0e7b7f9d4414984ccaa72bfb2ea39"
$sourceVaultValue = "/subscriptions/########-####-####-####-############/resourceGroups/sftestupgradegroup/providers/Microsoft.KeyVault/vaults/sftestupgradegroup"
$thumb = "BB796AA33BD9767E7DA27FE5182CF8FDEE714A70"

接下來,指定叢集的資源群組名稱,並且設定 templateFilePathparameterFilePath 位置:

注意

指定的資源群組必須已存在,且位於與您的 Key Vault 相同的區域中。

$resourceGroupName = "sftestupgradegroup"
$templateFilePath = "C:\Initial-TestClusterSetup.json"
$parameterFilePath = "C:\parameters.json"

最後,執行下列命令以部署初始測試叢集:

# Deploy the initial test cluster
New-AzResourceGroupDeployment `
    -ResourceGroupName $resourceGroupName `
    -TemplateFile $templateFilePath `
    -TemplateParameterFile $parameterFilePath `
    -CertificateThumbprint $thumb `
    -CertificateUrlValue $certUrlValue `
    -SourceVaultValue $sourceVaultValue `
    -Verbose

連線到新叢集並檢查健全狀態

連線至叢集,並確保其全部五個節點的狀況良好 (以您自己的值取代 clusterNamethumb 變數):

# Connect to the cluster
$clusterName = "sftestupgrade.southcentralus.cloudapp.azure.com:19000"
$thumb = "BB796AA33BD9767E7DA27FE5182CF8FDEE714A70"
Connect-ServiceFabricCluster `
    -ConnectionEndpoint $clusterName `
    -KeepAliveIntervalInSec 10 `
    -X509Credential `
    -ServerCertThumbprint $thumb  `
    -FindType FindByThumbprint `
    -FindValue $thumb `
    -StoreLocation CurrentUser `
    -StoreName My
# Check cluster health
Get-ServiceFabricClusterHealth

如此一來,我們已準備好開始進行升級程序。

使用升級的擴展集部署新的非主要節點類型

為了升級 (垂直調整) 節點類型,我們必須先部署新的節點類型,由新的擴展集和支援的資源作為後盾。 新的擴展集將會標示為非主要 (isPrimary: false),就像原始擴展集一樣。 如果您想要擴大主要節點類型,請參閱擴大 Service Fabric 叢集主要節點類型。 在下一節中建立的資源最終會成為叢集中的新節點類型,而且會刪除原始節點類型資源。

以升級的擴展集更新叢集範本

以下是針對新增新的節點類型和支援資源的原始叢集部署範本逐章節修改。

此步驟的大部分必要變更都已在 Step1-AddPrimaryNodeType.json (英文) 範本檔案中為您進行。 不過,必須進行額外的變更,才能讓範本檔案適用於非主要節點類型。 下列各節將詳細說明這些變更,而且會在您必須進行變更時提出這些變更。

注意

請確定您使用與原始節點類型、擴展集、負載平衡器、公用 IP 和原始非主要節點類型子網路不同的唯一名稱,因為這些資源會在程序稍後的步驟中刪除。

在現有虛擬網路中建立新的子網路

{
    "name": "[variables('subnet1Name')]",
    "properties": {
        "addressPrefix": "[variables('subnet1Prefix')]"
    }
}

使用唯一的 domainNameLabel 建立新的公用 IP

{
    "apiVersion": "[variables('publicIPApiVersion')]",
    "type": "Microsoft.Network/publicIPAddresses",
    "name": "[concat(variables('lbIPName'),'-',variables('vmNodeType1Name'))]",
    "location": "[variables('computeLocation')]",
    "properties": {
        "dnsSettings": {
            "domainNameLabel": "[concat(variables('dnsName'),'-','nt1')]"
        },
        "publicIPAllocationMethod": "Dynamic"
    },
    "tags": {
        "resourceType": "Service Fabric",
        "clusterName": "[parameters('clusterName')]"
    }
}

為公用 IP 建立新的負載平衡器

"dependsOn": [
    "[concat('Microsoft.Network/publicIPAddresses/',concat(variables('lbIPName'),'-',variables('vmNodeType1Name')))]"
]

建立新的虛擬機器擴展集 (具有升級的 VM 和 OS SKU)

節點類型參考

"nodeTypeRef": "[variables('vmNodeType1Name')]"

VM SKU

"sku": {
    "name": "[parameters('vmNodeType1Size')]",
    "capacity": "[parameters('nt1InstanceCount')]",
    "tier": "Standard"
}

OS SKU

"imageReference": {
    "publisher": "[parameters('vmImagePublisher1')]",
    "offer": "[parameters('vmImageOffer1')]",
    "sku": "[parameters('vmImageSku1')]",
    "version": "[parameters('vmImageVersion1')]"
}

此外,請確定您包含工作負載所需的任何其他延伸模組。

將新的非主要節點類型新增至叢集

現在新的節點類型 (vmNodeType1Name) 已經有自己的名稱、子網路、IP、負載平衡器和擴展集,可以重複使用來自原始節點類型的其他所有變數 (例如 nt0applicationEndPortnt0applicationStartPortnt0fabricTcpGatewayPort)。

在現有的範本檔案中,isPrimary 參數已根據擴大 Service Fabric 叢集主要節點類型指南設定為 true。 針對非主要節點類型,將 isPrimary 變更為 false

"name": "[variables('vmNodeType1Name')]",
"applicationPorts": {
    "endPort": "[variables('nt0applicationEndPort')]",
    "startPort": "[variables('nt0applicationStartPort')]"
},
"clientConnectionEndpointPort": "[variables('nt0fabricTcpGatewayPort')]",
"durabilityLevel": "Bronze",
"ephemeralPorts": {
    "endPort": "[variables('nt0ephemeralEndPort')]",
    "startPort": "[variables('nt0ephemeralStartPort')]"
},
"httpGatewayEndpointPort": "[variables('nt0fabricHttpGatewayPort')]",
"isPrimary": false,
"reverseProxyEndpointPort": "[variables('nt0reverseProxyEndpointPort')]",
"vmInstanceCount": "[parameters('nt1InstanceCount')]"

在您實作範本和參數檔案中的所有變更之後,請繼續下一節,以取得您的 Key Vault 參考,並將更新部署至您的叢集。

取得您的 Key Vault 參考

若要部署更新的設定,您需要數個儲存在 Key Vault 中的叢集憑證參考。 尋找這些值最簡單的方式是透過 Azure 入口網站。 您將需要:

  • 叢集憑證的 Key Vault URL。 從 Azure 入口網站的 Key Vault 中,選取 [憑證]> [您需要的憑證]> [祕密識別碼]

    $certUrlValue="https://sftestupgradegroup.vault.azure.net/secrets/sftestupgradegroup20200309235308/dac0e7b7f9d4414984ccaa72bfb2ea39"
    
  • 叢集憑證的指紋。 (如果您連線至初始叢集以檢查其健全狀態,您可能已經有這個項目。)在 Azure 入口網站中從相同的憑證刀鋒視窗 ([憑證]> [您需要的憑證]),複製 X.509 SHA-1 指紋 (十六進位)

    $thumb = "BB796AA33BD9767E7DA27FE5182CF8FDEE714A70"
    
  • Key Vault 的資源識別碼。 從 Azure 入口網站的 Key Vault 中,選取 [屬性]> [資源識別碼]

    $sourceVaultValue = "/subscriptions/########-####-####-####-############/resourceGroups/sftestupgradegroup/providers/Microsoft.KeyVault/vaults/sftestupgradegroup"
    

部署更新的範本

視需要調整 templateFilePath,然後執行以下命令:

# Deploy the new node type and its resources
$templateFilePath = "C:\Step1-AddPrimaryNodeType.json"
New-AzResourceGroupDeployment `
    -ResourceGroupName $resourceGroupName `
    -TemplateFile $templateFilePath `
    -TemplateParameterFile $parameterFilePath `
    -CertificateThumbprint $thumb `
    -CertificateUrlValue $certUrlValue `
    -SourceVaultValue $sourceVaultValue `
    -Verbose

當部署完成時,請再次檢查叢集健康情況,並確定兩個節點類型上的所有節點都狀況良好。

Get-ServiceFabricClusterHealth

將工作負載移轉至新的節點類型

等到所有應用程式都移至新的節點類型且狀況良好為止。

停用原始節點類型擴展集中的節點

當所有種子節點都移轉至新的擴展集之後,您就可以停用原始擴展集的節點。

# Disable the nodes in the original scale set.
$nodeType = "nt0vm"
$nodes = Get-ServiceFabricNode
Write-Host "Disabling nodes..."
foreach($node in $nodes)
{
  if ($node.NodeType -eq $nodeType)
  {
    $node.NodeName
    Disable-ServiceFabricNode -Intent RemoveNode -NodeName $node.NodeName -Force
  }
}

使用 Service Fabric Explorer 來監視原始擴展集中節點的進展,從 [停用中] 變成 [已停用] 狀態。 等候所有節點都到達 [已停用] 狀態。

停止已停用節點上的資料

現在您可以停止已停用節點上的資料。

# Stop data on the disabled nodes.
foreach($node in $nodes)
{
  if ($node.NodeType -eq $nodeType)
  {
    $node.NodeName
    Start-ServiceFabricNodeTransition -Stop -OperationId (New-Guid) -NodeInstanceId $node.NodeInstanceId -NodeName $node.NodeName -StopDurationInSeconds 10000
  }
}

移除原始節點類型,並清除其資源

我們已準備好移除原始節點類型及其相關聯的資源,以結束垂直調整程序。

移除原始擴展集

先移除節點類型的支援擴展集。

$scaleSetName = "nt0vm"
$scaleSetResourceType = "Microsoft.Compute/virtualMachineScaleSets"
Remove-AzResource -ResourceName $scaleSetName -ResourceType $scaleSetResourceType -ResourceGroupName $resourceGroupName -Force

刪除原始 IP 和負載平衡器資源

您現在可以刪除原始 IP 和負載平衡器資源。 在此步驟中,您也會更新 DNS 名稱。

注意

如果您已經使用 [標準] SKU 公用 IP 和負載平衡器,則此步驟是選擇性的。 在此情況下,相同負載平衡器下可能會有多個擴展集/節點類型。 執行下列命令,視需要修改 $lbname 值。

# Delete the original IP and load balancer resources
$lbName = "LB-sftestupgrade-nt0vm"
$lbResourceType = "Microsoft.Network/loadBalancers"
$ipResourceType = "Microsoft.Network/publicIPAddresses"
$oldPublicIpName = "PublicIP-LB-FE-nt0vm"
$newPublicIpName = "PublicIP-LB-FE-nt1vm"
$oldPublicIP = Get-AzPublicIpAddress -Name $oldPublicIpName  -ResourceGroupName $resourceGroupName
$nonPrimaryDNSName = $oldNonPrimaryPublicIP.DnsSettings.DomainNameLabel
$nonPrimaryDNSFqdn = $oldNonPrimaryPublicIP.DnsSettings.Fqdn
Remove-AzResource -ResourceName $lbName -ResourceType $lbResourceType -ResourceGroupName $resourceGroupName -Force
Remove-AzResource -ResourceName $oldPublicIpName -ResourceType $ipResourceType -ResourceGroupName $resourceGroupName -Force
$PublicIP = Get-AzPublicIpAddress -Name $newPublicIpName  -ResourceGroupName $resourceGroupName
$PublicIP.DnsSettings.DomainNameLabel = $nonPrimaryDNSName
$PublicIP.DnsSettings.Fqdn = $nonPrimaryDNSFqdn
Set-AzPublicIpAddress -PublicIpAddress $PublicIP

從原始節點類型中移除節點狀態

原始節點類型節點的 [健全狀態] 現在會顯示 [錯誤]。 從叢集中移除其節點狀態。

# Remove state of the obsolete nodes from the cluster
$nodeType = "nt0vm"
$nodes = Get-ServiceFabricNode
Write-Host "Removing node state..."
foreach($node in $nodes)
{
  if ($node.NodeType -eq $nodeType)
  {
    $node.NodeName
    Remove-ServiceFabricNodeState -NodeName $node.NodeName -Force
  }
}

Service Fabric Explorer 現在應該只會反映新節點類型 (nt1vm) 的五個節點,其 [健全狀態] 都是 [正常]。 接下來我們會更新範本以反映最新的變更並且重新部署,以進行補救。

更新部署範本以反映新的已擴大非主要節點類型

此步驟的大部分必要變更都已在 Step3-CleanupOriginalPrimaryNodeType.json (英文) 範本檔案中為您進行。 不過,必須進行額外的變更,才能讓範本檔案適用於非主要節點類型。 下列各節將詳細說明這些變更,而且會在您必須進行變更時提出這些變更。

更新叢集管理端點

更新部署範本上的叢集 managementEndpoint 以反映新的 IP (藉由使用 vmNodeType1Name 更新 vmNodeType0Name)。

  "managementEndpoint": "[concat('https://',reference(concat(variables('lbIPName'),'-',variables('vmNodeType1Name'))).dnsSettings.fqdn,':',variables('nt0fabricHttpGatewayPort'))]",

移除原始節點類型參考

從部署範本的 Service Fabric 資源中移除原始節點類型參考。

在現有的範本檔案中,isPrimary 參數已根據擴大 Service Fabric 叢集主要節點類型指南設定為 true。 針對非主要節點類型,將 isPrimary 變更為 false

"name": "[variables('vmNodeType0Name')]",
"applicationPorts": {
    "endPort": "[variables('nt0applicationEndPort')]",
    "startPort": "[variables('nt0applicationStartPort')]"
},
"clientConnectionEndpointPort": "[variables('nt0fabricTcpGatewayPort')]",
"durabilityLevel": "Bronze",
"ephemeralPorts": {
    "endPort": "[variables('nt0ephemeralEndPort')]",
    "startPort": "[variables('nt0ephemeralStartPort')]"
},
"httpGatewayEndpointPort": "[variables('nt0fabricHttpGatewayPort')]",
"isPrimary": false,
"reverseProxyEndpointPort": "[variables('nt0reverseProxyEndpointPort')]",
"vmInstanceCount": "[parameters('nt0InstanceCount')]"

設定健康情況原則以忽略現有的錯誤

僅限銀級以上的持久性叢集,請在叢集資源下新增 applicationDeltaHealthPolicies (如下所示),更新範本中的叢集資源,並將健康情況原則設為略過 fabric:/System 應用程式健康情況。 下列原則會略過現有錯誤,但不允許發生新的健康情況錯誤。

"upgradeDescription":  
{ 
 "forceRestart": false, 
 "upgradeReplicaSetCheckTimeout": "10675199.02:48:05.4775807", 
 "healthCheckWaitDuration": "00:05:00", 
 "healthCheckStableDuration": "00:05:00", 
 "healthCheckRetryTimeout": "00:45:00", 
 "upgradeTimeout": "12:00:00", 
 "upgradeDomainTimeout": "02:00:00", 
 "healthPolicy": { 
   "maxPercentUnhealthyNodes": 100, 
   "maxPercentUnhealthyApplications": 100 
 }, 
 "deltaHealthPolicy":  
 { 
   "maxPercentDeltaUnhealthyNodes": 0, 
   "maxPercentUpgradeDomainDeltaUnhealthyNodes": 0, 
   "maxPercentDeltaUnhealthyApplications": 0, 
   "applicationDeltaHealthPolicies":  
   { 
       "fabric:/System":  
       { 
           "defaultServiceTypeDeltaHealthPolicy":  
           { 
                   "maxPercentDeltaUnhealthyServices": 0 
           } 
       } 
   } 
 } 
}

移除原始節點類型的支援資源

從 ARM 範本和參數檔案中移除與原始節點類型相關的其他所有資源。 刪除下面這一行:

    "vmImagePublisher": {
      "value": "MicrosoftWindowsServer"
    },
    "vmImageOffer": {
      "value": "WindowsServer"
    },
    "vmImageSku": {
      "value": "2019-Datacenter"
    },
    "vmImageVersion": {
      "value": "latest"
    },

部署已完成的範本

最後,部署已修改的 Azure Resource Manager 範本。

# Deploy the updated template file
$templateFilePath = "C:\Step3-CleanupOriginalPrimaryNodeType"
New-AzResourceGroupDeployment `
    -ResourceGroupName $resourceGroupName `
    -TemplateFile $templateFilePath `
    -TemplateParameterFile $parameterFilePath `
    -CertificateThumbprint $thumb `
    -CertificateUrlValue $certUrlValue `
    -SourceVaultValue $sourceVaultValue `
    -Verbose

注意

此步驟需要一段時間,最多通常為兩個小時。 這項升級會將設定變更為 InfrastructureService,因此需要重新啟動節點。 在此情況下,會忽略 forceRestart。 參數 upgradeReplicaSetCheckTimeout 用於指定 Service Fabric 等待分割區轉為安全狀態 (若尚未處於安全狀態) 的時間上限。 當節點的所有分割區皆通過安全性檢查,Service Fabric 便會於該節點繼續進行升級。 參數 upgradeTimeout 的值可縮減為 6 小時,但應使用安全性最高的 12 小時。

部署完成之後,請在 Azure 入口網站中確認 Service Fabric 資源狀態為 [就緒]。 確認您可以連線到新的 Service Fabric Explorer 端點、[叢集健全狀態] 為 [正常],而且任何已部署的應用程式都能正常運作。

這樣一來,您就已經垂直調整叢集非主要節點類型!

下一步