2.4. 创建服务主体
由于 OpenShift Container Platform 及其安装程序使用 Azure Resource Manager 创建 Microsoft Azure 资源,因此您必须创建一个服务主体来代表它。
先决条件
- 安装或更新 Azure CLI。
- 您的 Azure 帐户具有您所用订阅所需的角色。
流程
注册您的环境:
$ az cloud register -n AzureStackCloud --endpoint-resource-manager <endpoint>1 - 1
- 指定 Azure Resource Manager 端点 'https://management.<region>.<fqdn>/'。
详情请查看 Microsoft 文档。
设置活跃环境:
$ az cloud set -n AzureStackCloud更新您的环境配置,以使用 Azure Stack Hub 的特定 API 版本:
$ az cloud update --profile 2019-03-01-hybrid登录 Azure CLI:
$ az login如果您在多租户环境中,还必须提供租户 ID。
如果您的 Azure 帐户使用订阅,请确定您使用正确的订阅:
查看可用帐户列表并记录您要用于集群的订阅的
tenantId值:$ az account list --refresh输出示例
[ { "cloudName": AzureStackCloud", "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": AzureStackCloud", "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": AzureStackCloud", "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 Contributor --name <service_principal> \1 --scopes /subscriptions/<subscription_id>2 --years <years>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 安装过程中需要这些值。