你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

创建和使用服务主体来部署 Azure Red Hat OpenShift 群集

若要与 Azure API 交互,Azure Red Hat OpenShift 群集需要 Microsoft Entra 服务主体。 此服务主体用于动态创建、管理或访问其他 Azure 资源,例如 Azure 负载均衡器或 Azure 容器注册表 (ACR)。 有关详细信息,请参阅 Microsoft Entra ID 中的应用程序对象和服务主体对象

本文介绍如何创建和使用服务主体来使用 Azure 命令行接口 (Azure CLI) 或 Microsoft 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 应用程序和服务主体。 确保保存应用程序(客户端)ID 和机密。