共用方式為


在 Azure Stack Edge Pro GPU 裝置的 Kubernetes 叢集上啟用 Azure Arc

適用於:Yes for Pro GPU SKUAzure Stack Edge Pro - GPUYes for Pro 2 SKUAzure Stack Edge Pro 2Yes for Pro R SKUAzure Stack Edge Pro RYes for Mini R SKUAzure Stack Edge Mini R

本文會說明如何在 Azure Stack Edge Pro 裝置現有的 Kubernetes 叢集上啟用 Azure Arc。

此程序假設您已閱讀並了解下列文章:

必要條件

請確定您已在 Azure Stack Edge Pro 裝置和您用來存取裝置的用戶端上,完成下列必要條件:

針對裝置

  1. 您有 1 個節點 Azure Stack Edge Pro 裝置的登入認證。

    1. 裝置已啟動。 請參閱啟動裝置
    2. 裝置具有透過 Azure 入口網站設定的計算角色,且具有 Kubernetes 叢集。 請參閱設定計算
  2. 您具有訂用帳戶的擁有者存取權。 您在服務主體的角色指派步驟期間,會需要此存取權。

針對存取裝置的用戶端

  1. 您有用來存取 Azure Stack Edge Pro 裝置的 Windows 用戶端系統。

    • 用戶端執行 Windows PowerShell 5.0 以上版本。 若要下載最新版本的 Windows PowerShell,請前往安裝 Windows PowerShell

    • 您也可以有搭配支援作業系統的其他用戶端。 本文說明使用 Windows 用戶端時的程序。

  2. 您已完成在 Azure Stack Edge Pro 裝置上存取 Kubernetes 叢集中所描述的程序。 您已經:

    • 已將 kubectl 安裝在用戶端上。
    • 請確定 kubectl 用戶端版本與在 Azure Stack Edge Pro 裝置上執行的 Kubernetes 主要版本相比,沒有差超過一個版本。
      • 使用 kubectl version 檢查用戶端上執行的 kubectl 版本。 記下完整版本。

      • 在 Azure Stack Edge Pro 裝置的本機 UI 中,前往 [軟體更新],並記下 Kubernetes 伺服器版本號碼。

        Verify Kubernetes server version number

      • 確認這兩個版本相容。

註冊 Kubernetes 資源提供者

在 Kubernetes 叢集上啟用 Azure Arc 之前,您必須針對您的訂用帳戶,啟用和註冊 Microsoft.KubernetesMicrosoft.KubernetesConfiguration

  1. 若要啟用資源提供者,請在 Azure 入口網站中,前往您打算用於部署的訂用帳戶。 前往 [資源提供者]

  2. 在右窗格中,搜尋您要新增的提供者。 在此範例中,是 Microsoft.KubernetesMicrosoft.KubernetesConfiguration

    Register Kubernetes resource providers

  3. 選取資源提供者,然後從命令列頂端選取 [註冊]。 註冊作業需要幾分鐘的時間。

    Register Kubernetes resource providers 2

  4. 重新整理 UI,直到您看到資源提供者已註冊為止。 針對這兩個資源提供者重複此流程。

    Register Kubernetes resource providers 3

您也可以透過 az cli 註冊資源提供者。 如需詳細資訊,請參閱為已啟用 Azure Arc 的 Kubernetes 註冊兩個提供者

建立服務主體,指派角色

  1. 請確定您有 Subscription ID,以及您用於 Azure Stack Edge 服務資源部署的資源群組名稱。 若要取得訂用帳戶識別碼,請前往 Azure 入口網站中的 Azure Stack Edge 資源。 瀏覽至 [概觀] 和 [基本資訊]

    Get subscription ID

    若要取得資源群組名稱,請前往 [屬性]

    Get resource group name

  2. 若要建立服務主體,請透過 az cli 使用下列命令。

    az ad sp create-for-rbac --name "<Informative name for service principal>"

    如需如何登入 az cli 的資訊,請參閱在 Azure 入口網站中啟動 Cloud Shell。 如果在本機用戶端上使用 az cli 來建立服務主體,請確定您執行的是 2.25 版或更新版本。

    以下是範例。

    PS /home/user> az ad sp create-for-rbac --name "https://azure-arc-for-ase-k8s"
    {
      "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "displayName": "azure-arc-for-ase-k8s",
      "name": "https://azure-arc-for-ase-k8s",
      "password": "<password>",
      "tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    }
    PS /home/user>
    
  3. 記下 appIDnamepasswordtenantID,因為您將會使用這些值作為下一個命令的輸入內容。

  4. 建立新的服務主體之後,將 Kubernetes Cluster - Azure Arc Onboarding 角色指派給新建立的主體。 這是內建的 Azure 角色 (在命令中使用角色識別碼),權限受到限制。 使用下列命令:

    az role assignment create --role 34e09817-6cbe-4d01-b1a2-e0eac5743d41 --assignee <appId-from-service-principal> --scope /subscriptions/<SubscriptionID>/resourceGroups/<Resource-group-name>

    以下是範例。

    PS /home/user> az role assignment create --role 34e09817-6cbe-4d01-b1a2-e0eac5743d41 --assignee xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --scope /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myaserg1
    {
      "canDelegate": null,
      "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myaserg1/providers/Microsoft.Authorization/roleAssignments/59272f92-e5ce-4aeb-9c0c-62532d8caf25",
      "name": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "principalId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "principalType": "ServicePrincipal",
      "resourceGroup": "myaserg1",
      "roleDefinitionId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleDefinitions/34e09817-6cbe-4d01-b1a2-e0eac5743d41",
      "scope": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myaserg1",
      "type": "Microsoft.Authorization/roleAssignments"
    }
    PS /home/user>
    

在 Kubernetes 叢集上啟用 Arc

請遵循下列步驟來設定 Kubernetes 叢集,以進行 Azure Arc 管理:

  1. 連線到裝置的 PowerShell 介面

  2. 輸入:

    Set-HcsKubernetesAzureArcAgent -SubscriptionId "<Your Azure Subscription Id>" -ResourceGroupName "<Resource Group Name>" -ResourceName "<Azure Arc resource name (shouldn't exist already)>" -Location "<Region associated with resource group>" -TenantId "<Tenant Id of service principal>" -ClientId "<App id of service principal>"

    執行此命令時,會顯示後續提示,請您輸入 ClientSecret。 請輸入服務主體的密碼。

    如果您使用 Azure 公用以外的雲端,請新增 CloudEnvironment 參數。 您可以將此參數設定為 AZUREPUBLICCLOUDAZURECHINACLOUDAZUREGERMANCLOUDAZUREUSGOVERNMENTCLOUD

    注意

    • 若要在裝置上部署 Azure Arc,請確定您使用的是 Azure Arc 的支援區域
    • 使用 az account list-locations 命令來找出要傳入 Set-HcsKubernetesAzureArcAgent Cmdlet 的確切位置名稱。 位置名稱通常會有格式設定,不含任何空格。
    • ClientIdClientSecret 是必要資訊。

    以下是範例:

    [10.100.10.10]: PS>Set-HcsKubernetesAzureArcAgent -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -ResourceGroupName "myaserg1" -ResourceName "myasetestresarc" -Location "westeurope" -TenantId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -ClientId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    
    WARNING: A script or application on the remote computer 10.126.76.0 is sending a prompt request. When you are prompted,
    enter sensitive information, such as credentials or passwords, only if you trust the remote computer and the
    application or script that is requesting the data.
    
    cmdlet Set-HcsKubernetesAzureArcAgent at command pipeline position 1
    
    Supply values for the following parameters:
    ClientSecret: **********************************
    [10.100.10.10]: PS>
    

    在 Azure 入口網站中,應該使用您在上述命令中提供的名稱來建立資源。

    Go to Azure Arc resource

  3. 若要確認已成功啟用 Azure Arc,請從 PowerShell 介面執行下列命令:

    kubectl get deployments,pods -n azure-arc

    以下是範例輸出,顯示在 azure-arc 命名空間中,部署於 Kubernetes 叢集上的 Azure Arc 代理程式。

    [10.128.44.240]: PS>kubectl get deployments,pods -n azure-arc
    NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/cluster-metadata-operator   1/1     1            1           13d
    deployment.apps/clusterconnect-agent        1/1     1            1           13d
    deployment.apps/clusteridentityoperator     1/1     1            1           13d
    deployment.apps/config-agent                1/1     1            1           13d
    deployment.apps/controller-manager          1/1     1            1           13d
    deployment.apps/extension-manager           1/1     1            1           13d
    deployment.apps/flux-logs-agent             1/1     1            1           13d
    deployment.apps/kube-aad-proxy              1/1     1            1           13d
    deployment.apps/metrics-agent               1/1     1            1           13d
    deployment.apps/resource-sync-agent         1/1     1            1           13d
    
    NAME                                            READY   STATUS    RESTARTS   AGE
    pod/cluster-metadata-operator-9568b899c-2stjn   2/2     Running   0          13d
    pod/clusterconnect-agent-576758886d-vggmv       3/3     Running   0          13d
    pod/clusteridentityoperator-6f59466c87-mm96j    2/2     Running   0          13d
    pod/config-agent-7cbd6cb89f-9fdnt               2/2     Running   0          13d
    pod/controller-manager-df6d56db5-kxmfj          2/2     Running   0          13d
    pod/extension-manager-58c94c5b89-c6q72          2/2     Running   0          13d
    pod/flux-logs-agent-6db9687fcb-rmxww            1/1     Running   0          13d
    pod/kube-aad-proxy-67b87b9f55-bthqv             2/2     Running   0          13d
    pod/metrics-agent-575c565fd9-k5j2t              2/2     Running   0          13d
    pod/resource-sync-agent-6bbd8bcd86-x5bk5        2/2     Running   0          13d
    [10.128.44.240]: PS>
    

此處會顯示這些代理程式的概念概觀。

從 Kubernetes 叢集移除 Arc

若要移除 Azure Arc 管理,請遵循下列步驟:

    1. 連線到裝置的 PowerShell 介面
  1. 輸入:

    Remove-HcsKubernetesAzureArcAgent

注意

根據預設,從 Git 存放庫刪除資源 yamls 時,系統不會從 Kubernetes 叢集刪除對應的資源。 您需要在 Arc OperatorParams 中設定 --sync-garbage-collection,才能在資源從 git 存放庫中刪除時,允許刪除資源。 如需詳細資訊,請參閱刪除設定

下一步

若要了解如何執行 Azure Arc 部署,請參閱透過 Azure Stack Edge Pro 裝置上的 GitOps,使用 Redis 部署無狀態 PHP Guestbook 應用程式