建立和使用服務主體來部署 Azure Red Hat OpenShift 叢集

若要與 Azure API 互動,Azure Red Hat OpenShift 叢集需要 Microsoft Entra 服務主體。 此服務主體可用來動態建立、管理或存取其他 Azure 資源,例如 Azure 負載平衡器或 Azure Container Registry (ACR)。 如需詳細資訊,請參閱 Microsoft Entra ID 中的應用程式和服務主體物件。

本文說明如何使用 Azure 命令列介面 (Azure CLI) 或Azure 入口網站來建立和使用服務主體來部署 Azure Red Hat OpenShift 叢集。

注意

除非設定較長的期間,否則服務主體會在一年內到期。 如需延伸服務主體到期期限的資訊,請參閱 輪替 Azure Red Hat OpenShift (ARO) 叢集 的服務主體認證。

建立和使用服務主體

下列各節說明如何建立和使用服務主體來部署 Azure Red Hat OpenShift 叢集。

必要條件 - Azure CLI

如果您使用 Azure CLI,則需要安裝及設定 Azure CLI 2.30.0 版或更新版本。 執行 az --version 以尋找版本。 如果您需要安裝或升級,請參閱 安裝 Azure CLI

建立資源群組 - Azure CLI

執行下列 Azure CLI 命令,以建立 Azure Red Hat OpenShift 叢集所在的資源群組。

AZ_RG=$(az group create -n test-aro-rg -l eastus2 --query name -o tsv)

建立服務主體並指派角色型存取控制 (RBAC) - Azure CLI

若要將參與者角色指派給 Azure Red Hat OpenShift 資源群組,請執行下列命令。

# Get Azure subscription ID
AZ_SUB_ID=$(az account show --query id -o tsv) 
# Create a service principal with contributor role and scoped to the Azure Red Hat OpenShift resource group 
az ad sp create-for-rbac -n "test-aro-SP" --role contributor --scopes "/subscriptions/${AZ_SUB_ID}/resourceGroups/${AZ_RG}"

注意

每個 Azure RedHat OpenShift (ARO) 叢集的服務主體都必須是唯一的。

輸出類似下列範例:

{ 

  "appId": "", 

  "displayName": "myAROClusterServicePrincipal", 

  "name": "http://myAROClusterServicePrincipal", 

  "password": "yourpassword", 

  "tenant": "yourtenantname"

}

重要

此服務主體只允許 Azure Red Hat OpenShift 叢集所在的資源群組參與者。 如果您的 VNet 位於另一個資源群組中,您也必須將服務主體參與者角色指派給該資源群組。 您也需要在上面建立的資源群組中建立 Azure Red Hat OpenShift 叢集。

若要使用 Azure 入口網站將許可權授與現有的服務主體,請參閱 在入口網站中 建立 Microsoft Entra 應用程式和服務主體。

使用 Azure 入口網站 建立服務主體

若要透過Azure 入口網站建立 Azure Red Hat OpenShift 叢集的服務主體,請參閱 使用入口網站建立可存取資源的 Microsoft Entra 應用程式和服務主體。 請務必儲存應用程式(用戶端)識別碼和秘密。