在已啟用 Azure Arc 的 Kubernetes 上建立和管理自訂位置

自定義 位置 功能可讓您將已啟用 Azure Arc 的 Kubernetes 叢集設定為部署 Azure 供應專案實例的目標位置。 可在自定義位置上部署的 Azure 供應專案範例包括資料庫,例如 Azure Arc 和已啟用 Azure Arc 的 PostgreSQL 伺服器所啟用 SQL 受管理執行個體,或應用程式實例,例如 App Services、Functions、事件方格、Logic Apps 和 API 管理。

自定義位置具有一對一對應至已啟用 Azure Arc 的 Kubernetes 叢集中命名空間的對應。 Azure 資源與 Azure 角色型存取控制 (Azure RBAC) 結合的自定義位置可用來將細微的許可權授與應用程式開發人員或資料庫管理員,讓他們能夠在已啟用 Arc 的 Kubernetes 叢集之上部署資料庫或應用程式實例等資源。

在本文中,您將瞭解如何在已啟用 Arc 的 Kubernetes 叢集上啟用自定義位置,以及如何建立自定義位置。

必要條件

  • 安裝或升級 Azure CLI 至最新版本。

  • 安裝下列 Azure CLI 延伸模組的最新版本:

    • connectedk8s

    • k8s-extension

    • customlocation

      az extension add --name connectedk8s
      az extension add --name k8s-extension
      az extension add --name customlocation
      

      如果您已安裝 connectedk8sk8s-extensioncustomlocation 延伸模組,請使用下列命令更新至 最新版本

      az extension update --name connectedk8s
      az extension update --name k8s-extension
      az extension update --name customlocation
      
  • 確認已完成的 Microsoft.ExtendedLocation提供者註冊。

    1. 輸入下列命令:

      az provider register --namespace Microsoft.ExtendedLocation
      
    2. 監視註冊程序。 註冊最多可能需要 10 分鐘的時間。

      az provider show -n Microsoft.ExtendedLocation -o table
      

      註冊之後, RegistrationState 狀態將會有 Registered 值。

  • 確認您有已啟用 Azure Arc 的現有 Kubernetes 連線叢集,並將 代理程序 升級至最新版本。 確認您將執行本文所述的命令的電腦具有 kubeconfig 指向此叢集的檔案。

在您的叢集上啟用自定義位置

提示

自定義位置功能相依於 叢集連線 功能。 這兩個功能都必須在叢集中啟用,自定義位置才能運作。

如果您是以 Microsoft Entra 使用者身分登入 Azure CLI,請使用下列命令:

az connectedk8s enable-features -n <clusterName> -g <resourceGroupName> --features cluster-connect custom-locations

如果您在使用服務主體登入 Azure CLI 時執行上述命令,您可能會發現下列警告:

Unable to fetch oid of 'custom-locations' app. Proceeding without enabling the feature. Insufficient privileges to complete the operation.

這是因為服務主體沒有許可權可取得 Azure Arc 服務所使用應用程式的相關信息。 若要避免此錯誤,請完成下列步驟:

  1. 使用使用者帳戶登入 Azure CLI。 objectId使用下列命令擷取 Azure Arc 服務所使用的 Microsoft Entra 應用程式或 id

    az ad sp show --id bc313c14-388c-4e7d-a58e-70017303ee3b --query id -o tsv
    
  2. 使用服務主體登入 Azure CLI。 <objectId>使用上一個步驟中的 或 id 值,在叢集上啟用自定義位置:

    az connectedk8s enable-features -n <cluster-name> -g <resource-group-name> --custom-locations-oid <objectId/id> --features cluster-connect custom-locations
    

建立自定義位置

  1. 部署您想要在叢集上安裝的 Azure 服務執行個體的 Azure 服務叢集擴充功能:

  2. 取得已啟用 Azure Arc 的 Kubernetes 叢集的 Azure Resource Manager 識別碼,於稍後步驟中參考為 connectedClusterId

    az connectedk8s show -n <clusterName> -g <resourceGroupName>  --query id -o tsv
    
  3. 取得您部署至已啟用 Azure Arc 的 Kubernetes 叢集之叢集延伸模組的 Azure Resource Manager 標識符,後續步驟中參考如下 extensionId

    az k8s-extension show --name <extensionInstanceName> --cluster-type connectedClusters -c <clusterName> -g <resourceGroupName>  --query id -o tsv
    
  4. 藉由參考已啟用 Azure Arc 的 Kubernetes 叢集和延伸模組來建立自定義位置:

    az customlocation create -n <customLocationName> -g <resourceGroupName> --namespace <name of namespace> --host-resource-id <connectedClusterId> --cluster-extension-ids <extensionId> 
    
    • 必要參數:

      參數名稱 描述
      --name, --n 自訂位置的名稱。
      --resource-group, --g 自訂位置的資源群組。
      --namespace 系結至所建立自定義位置之叢集中的命名空間。
      --host-resource-id 已啟用 Azure Arc 的 Kubernetes 叢集 (已連線叢集) 的 Azure Resource Manager 標識符。
      --cluster-extension-ids 安裝在聯機叢集上之叢集擴充實例的 Azure Resource Manager 標識符。 針對多個延伸模組,提供以空格分隔的叢集擴充功能標識符清單
    • 選擇性參數:

      參數名稱 描述
      --location, --l Azure 中 Azure Resource Manager 資源自訂位置的位置。 如果未指定,則會使用聯機叢集的位置。
      --tags 以格式 key[=value]分隔標記的空間分隔清單。 使用'' 清除現有的標記。
      --kubeconfig kubeconfig叢集 管理員。

顯示自定義位置的詳細數據

若要顯示自訂位置的詳細資料,請使用下列命令:

az customlocation show -n <customLocationName> -g <resourceGroupName> 

列出自定義位置

若要列出資源群組中的所有自訂位置,請使用下列命令:

az customlocation list -g <resourceGroupName> 

更新自定義位置

update使用 命令為 新增值--tags,或將新的 --cluster-extension-ids 新增至自定義位置,同時保留標記和相關聯叢集延伸模組的現有值。

az customlocation update -n <customLocationName> -g <resourceGroupName> --namespace <name of namespace> --host-resource-id <connectedClusterId> --cluster-extension-ids <extensionIds> 

修補自定義位置

patch使用 命令來取代 或--tags的現有值--cluster-extension-ids。 不會保留先前的值。

az customlocation patch -n <customLocationName> -g <resourceGroupName> --namespace <name of namespace> --host-resource-id <connectedClusterId> --cluster-extension-ids <extensionIds> 

刪除自定義位置

若要刪除自訂位置,請使用下列命令:

az customlocation delete -n <customLocationName> -g <resourceGroupName> 

疑難排解

如果自定義位置建立失敗,並出現錯誤 Unknown proxy error occurred,請修改您的網路原則,以允許命名空間內的 azure-arc Pod 對 Pod 內部通訊。 請務必同時將命名空間新增 azure-arc 為已設定原則之無 Proxy 排除清單的一部分。

下一步