建立一個 Service Fabric 叢集資源管理範本

Azure Service Fabric 叢集 是一組透過網絡連接的虛擬機器,其中可部署和管理您的微服務。 在 Azure 中執行的 Service Fabric 叢集是 Azure 資源,並使用 Resource Manager 進行部署、管理及監視。 本文說明如何為在 Azure 中執行的 Service Fabric 叢集建立 Resource Manager 範本。 範本完成時,您可以在 Azure 上部署叢集。

叢集安全性是在叢集剛設置時設定的,之後無法更改。 設定叢集之前,請閱讀 Service Fabric 叢集安全性案例。 在 Azure 中,Service Fabric 使用 x509 憑證來保護您的叢集與其端點、驗證用戶端,以及加密資料。 Microsoft Entra ID 也建議您使用 Azure Active Directory 來保護對管理端點的存取。 必須在建立叢集之前先建立 Microsoft Entra 租用戶與使用者。 如需詳細資訊,請閱讀設定 Microsoft Entra ID 以驗證用戶端。

在部署生產叢集以執行生產工作負載之前,請務必先閱讀 生產整備檢查清單。

備註

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 開始使用前,請參閱安裝 Azure PowerShell。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az。

建立 Resource Manager 範本

您可以在 GitHub 上的 Azure 範例中取得 Resource Manager 範本範例。 這些範本可以用作叢集範本的起點。

本文使用 五個節點的安全叢集 範例範本和範本參數。 將 azuredeploy.json 和 azuredeploy.parameters.json 下載到您的電腦,並在您慣用的文字編輯器中開啟這兩個檔案。

備註

針對國家雲端(Azure 政府雲,由 21Vianet 營運的 Microsoft Azure,以及 Azure 德國雲),您應該將下列內容 fabricSettings 新增至您的範本:AADLoginEndpoint、AADTokenEndpointFormat 和 AADCertEndpointFormat。

新增憑證

你可以透過參考包含憑證金鑰的金鑰庫,將憑證加入叢集資源管理器範本。 在 Resource Manager 樣本參數檔案中新增這些密鑰保存庫參數和值 (azuredeploy.parameters.json)。

將所有憑證都新增到虛擬機器擴展集 osProfile

叢集中安裝的每個憑證都必須在擴展集資源的 osProfile 區段中設定(Microsoft.Compute/virtualMachineScaleSets)。 此動作會指示資源提供者在 VM 上安裝憑證。 這個安裝同時包含叢集憑證和您計畫用於應用程式的任何應用程式安全性憑證:

{
  "apiVersion": "[variables('vmssApiVersion')]",
  "type": "Microsoft.Compute/virtualMachineScaleSets",
  ...
  "properties": {
    ...
    "osProfile": {
      ...
      "secrets": [
        {
          "sourceVault": {
            "id": "[parameters('sourceVaultValue')]"
          },
          "vaultCertificates": [
            {
              "certificateStore": "[parameters('clusterCertificateStorevalue')]",
              "certificateUrl": "[parameters('clusterCertificateUrlValue')]"
            },
            {
              "certificateStore": "[parameters('applicationCertificateStorevalue')",
              "certificateUrl": "[parameters('applicationCertificateUrlValue')]"
            },
            ...
          ]
        }
      ]
    }
  }
}

設定 Service Fabric 叢集憑證

不論是在 Service Fabric 叢集資源 (Microsoft.ServiceFabric/clusters) 中,還是在虛擬機器擴展集資源中虛擬機器擴展集的 Service Fabric 延伸模組中,都必須設定叢集驗證憑證。 這種安排可讓 Service Fabric 資源提供者設定它,以便用於管理端點的叢集驗證和伺服器驗證。

將憑證資訊新增至虛擬機器擴展集資源

{
  "apiVersion": "[variables('vmssApiVersion')]",
  "type": "Microsoft.Compute/virtualMachineScaleSets",
  ...
  "properties": {
    ...
    "virtualMachineProfile": {
      "extensionProfile": {
        "extensions": [
          {
            "name": "[concat('ServiceFabricNodeVmExt_',variables('vmNodeType0Name'))]",
            "properties": {
              ...
              "settings": {
                ...
                "certificate": {
                  "commonNames": ["[parameters('certificateCommonName')]"],
                  "x509StoreName": "[parameters('clusterCertificateStoreValue')]"
                },
                ...
              }
            }
          }
        ]
      }
    }
  }
}

將憑證資訊新增至 Service Fabric 叢集資源

{
  "apiVersion": "2018-02-01",
  "type": "Microsoft.ServiceFabric/clusters",
  "name": "[parameters('clusterName')]",
  "location": "[parameters('clusterLocation')]",
  "dependsOn": [
    "[concat('Microsoft.Storage/storageAccounts/', variables('supportLogStorageAccountName'))]"
  ],
  "properties": {
    "certificateCommonNames": {
        "commonNames": [
        {
            "certificateCommonName": "[parameters('certificateCommonName')]",
            "certificateIssuerThumbprint": ""
        }
        ],
        "x509StoreName": "[parameters('certificateStoreValue')]"
    },
    ...
  }
}

新增 Microsoft Entra 組態,以使用 Microsoft Entra 標識符進行用戶端存取

你可以透過參考包含憑證金鑰的金鑰庫,將 Microsoft Entra 設定加入叢集資源管理器範本。 在 Resource Manager 樣本參數檔案中新增這些Microsoft Entra 參數和值 (azuredeploy.parameters.json)。

備註

在 Linux 上,必須在建立叢集之前先建立 Microsoft Entra 租用戶與使用者。 如需詳細資訊,請閱讀設定 Microsoft Entra ID 以驗證用戶端。

{
  "apiVersion": "2018-02-01",
  "type": "Microsoft.ServiceFabric/clusters",
  "name": "[parameters('clusterName')]",
  ...
  "properties": {
    "certificateCommonNames": {
        "commonNames": [
        {
            "certificateCommonName": "[parameters('certificateCommonName')]",
            "certificateIssuerThumbprint": ""
        }
        ],
        "x509StoreName": "[parameters('certificateStoreValue')]"
    },
    ...
    "azureActiveDirectory": {
      "tenantId": "[parameters('aadTenantId')]",
      "clusterApplication": "[parameters('aadClusterApplicationId')]",
      "clientApplication": "[parameters('aadClientApplicationId')]"
    },
    ...
  }
}

將值填入參數檔案中

最後,使用金鑰保存庫的輸出值,並Microsoft Entra PowerShell 命令來填入參數檔案。

如果你打算使用 Azure Service Fabric 的 RM PowerShell 模組,那你不需要填寫叢集憑證資訊。 如果您想要讓系統產生叢集安全性的自我簽署憑證,只要將它們保留為 Null 即可。

備註

若要讓 RM 模組挑選並填入這些空的參數值,參數名稱與下列名稱非常相符

"clusterCertificateThumbprint": {
    "value": ""
},
"certificateCommonName": {
    "value": ""
},
"clusterCertificateUrlValue": {
    "value": ""
},
"sourceVaultvalue": {
    "value": ""
},

如果你使用應用程式憑證或使用已上傳到金鑰庫的現有叢集,你需要取得這些資訊並填充。

RM 模組無法幫你產生 Microsoft Entra 設定,所以如果你打算用 Microsoft Entra ID 來存取客戶端,就必須先填入它。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        ...
        "clusterCertificateStoreValue": {
            "value": "My"
        },
        "clusterCertificateThumbprint": {
            "value": "<thumbprint>"
        },
        "clusterCertificateUrlValue": {
            "value": "https://myvault.vault.azure.net:443/secrets/myclustercert/4d087088df974e869f1c0978cb100e47"
        },
        "applicationCertificateStorevalue": {
            "value": "My"
        },
        "applicationCertificateUrlValue": {
            "value": "https://myvault.vault.azure.net:443/secrets/myapplicationcert/2e035058ae274f869c4d0348ca100f08"
        },
        "sourceVaultvalue": {
            "value": "/subscriptions/<guid>/resourceGroups/mycluster-keyvault/providers/Microsoft.KeyVault/vaults/myvault"
        },
        "aadTenantId": {
            "value": "<guid>"
        },
        "aadClusterApplicationId": {
            "value": "<guid>"
        },
        "aadClientApplicationId": {
            "value": "<guid>"
        },
        ...
    }
}

測試您的範本

使用下列 PowerShell 命令,以參數檔案測試 Resource Manager 範本:

Test-AzResourceGroupDeployment -ResourceGroupName "myresourcegroup" -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json

如果您遇到問題並取得神秘訊息,請使用 「-Debug」 作為選項。

Test-AzResourceGroupDeployment -ResourceGroupName "myresourcegroup" -TemplateFile .\azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json -Debug

下圖說明您的金鑰保存庫和Microsoft Entra 組態符合 Resource Manager 範本的位置。

Resource Manager 相依性對應

後續步驟

既然您已擁有叢集的範本,請瞭解如何 將叢集部署至 Azure。 如果您尚未這麼做,請先閱讀 生產整備檢查清單 ,再部署生產叢集。

若要瞭解本文中所部署資源的 JSON 語法和屬性,請參閱: