2.6. 创建服务主体
由于 OpenShift Container Platform 及其安装程序使用 Azure Resource Manager 创建 Microsoft Azure 资源,因此您必须创建一个服务主体来代表它。
先决条件
流程
登录 Azure CLI:
$ az login如果您的 Azure 帐户使用订阅,请确定您使用正确的订阅:
查看可用帐户列表并记录您要用于集群的订阅的
tenantId值:$ az account list --refresh输出示例
[ { "cloudName": "AzureCloud", "id": "9bab1460-96d5-40b3-a78e-17b15e978a80", "isDefault": true, "name": "Subscription Name", "state": "Enabled", "tenantId": "6057c7e9-b3ae-489d-a54e-de3f6bf6a8ee", "user": { "name": "you@example.com", "type": "user" } } ]查看您的活跃帐户详情,确认
tenantId值与您要使用的订阅匹配:$ az account show输出示例
{ "environmentName": "AzureCloud", "id": "9bab1460-96d5-40b3-a78e-17b15e978a80", "isDefault": true, "name": "Subscription Name", "state": "Enabled", "tenantId": "6057c7e9-b3ae-489d-a54e-de3f6bf6a8ee",1 "user": { "name": "you@example.com", "type": "user" } }- 1
- 确保
tenantId参数的值是正确的订阅 ID。
如果您使用的订阅不正确,请更改活跃的订阅:
$ az account set -s <subscription_id>1 - 1
- 指定订阅 ID。
验证订阅 ID 更新:
$ az account show输出示例
{ "environmentName": "AzureCloud", "id": "33212d16-bdf6-45cb-b038-f6565b61edda", "isDefault": true, "name": "Subscription Name", "state": "Enabled", "tenantId": "8049c7e9-c3de-762d-a54e-dc3f6be6a7ee", "user": { "name": "you@example.com", "type": "user" } }
-
记录输出中的
tenantId和id参数值。OpenShift Container Platform 安装过程中需要这些值。 为您的帐户创建服务主体:
$ az ad sp create-for-rbac --role <role_name> \1 --name <service_principal> \2 --scopes /subscriptions/<subscription_id>3 输出示例
Creating 'Contributor' role assignment under scope '/subscriptions/<subscription_id>' The output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control. For more information, see https://aka.ms/azadsp-cli { "appId": "ac461d78-bf4b-4387-ad16-7e32e328aec6", "displayName": <service_principal>", "password": "00000000-0000-0000-0000-000000000000", "tenantId": "8049c7e9-c3de-762d-a54e-dc3f6be6a7ee" }-
记录前面输出中
appId和password参数的值。OpenShift Container Platform 安装过程中需要这些值。 如果您将
Contributor角色应用到服务主体,请运行以下命令来分配User Administrator Access角色:$ az role assignment create --role "User Access Administrator" \ --assignee-object-id $(az ad sp show --id <appId> --query id -o tsv)1 - 1
- 为您的服务主体指定
appId参数值。