Share via


快速入門:使用 Azure Resource Manager 範本或 Bicep 檔案部署 Azure Red Hat OpenShift 叢集

本快速入門說明如何使用 Azure Resource Manager 範本 (ARM 範本) 或 Bicep 來建立 Azure Red Hat OpenShift 叢集。 您可以使用 PowerShell 或 Azure 命令行介面 (Azure CLI) 來部署 Azure Red Hat OpenShift 叢集。

Azure Resource Manager 範本是 JavaScript 物件表示法 (JSON) 檔案,可定義專案的基礎結構和組態。 範本使用宣告式語法。 您不需要撰寫程式設計命令順序來建立部署,即可描述預定的部署。

Bicep 是使用宣告式語法來部署 Azure 資源的特定領域語言 (DSL)。 在 Bicep 檔案中,您會定義要部署至 Azure 的基礎結構,然後在整個開發生命週期中使用該檔案,以重複部署您的基礎結構。 您的資源會以一致的方式進行部署。

必要條件

  • 需要具作用中訂用帳戶的 Azure 帳戶。 若您還沒有帳戶,可以免費建立帳戶

  • 能夠指派使用者存取 管理員 istrator 和參與者角色。 如果您缺少這項功能,請連絡您的 Microsoft Entra 系統管理員以管理角色。

  • Red Hat 帳戶。 如果您沒有帳戶,則必須 註冊帳戶

  • Azure Red Hat OpenShift 叢集的提取密碼。 從 Red Hat OpenShift 叢集管理員網站下載提取秘密檔案。

  • 如果您想要在本機執行 Azure PowerShell 程式代碼, Azure PowerShell

  • 如果您想要在本機執行 Azure CLI 程式代碼:

    • Bash 殼層(例如 Git Bash,包含在 Git for Windows)。
    • Azure CLI

建立 ARM 範本或 Bicep 檔案

選擇 Azure Resource Manager 樣本 (ARM 範本) 或 Azure Bicep 檔案。 然後,您可以使用 Azure 命令行 (azure-cli) 或 PowerShell 來部署範本。

建立 ARM 範本

下列範例示範針對 Azure RedHat OpenShift 叢集進行設定時,ARM 範本應該如何看起來。

此樣本會定義三個 Azure 資源:

您可以在 Red Hat OpenShift 網站上找到更多 Azure Red Hat OpenShift 範例。

將下列範例儲存為 azuredeploy.bicep

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "location" : {
        "type": "string",
        "defaultValue": "eastus",
        "metadata": {
          "description": "Location"
        }
      },
      "domain": {
          "type": "string",
          "defaultValue": "",
          "metadata": {
              "description": "Domain Prefix"
          }
      },
      "pullSecret": {
          "type": "string",
          "metadata": {
              "description": "Pull secret from cloud.redhat.com. The json should be input as a string"
          }
      },
      "clusterVnetName": {
          "type": "string",
          "defaultValue": "aro-vnet",
          "metadata": {
              "description": "Name of ARO vNet"
          }
      },
      "clusterVnetCidr": {
          "type": "string",
          "defaultValue": "10.100.0.0/15",
          "metadata": {
              "description": "ARO vNet Address Space"
          }
      },
      "workerSubnetCidr": {
          "type": "string",
          "defaultValue": "10.100.70.0/23",
          "metadata": {
              "description": "Worker node subnet address space"
          }
      },
      "masterSubnetCidr": {
          "type": "string",
          "defaultValue": "10.100.76.0/24",
          "metadata": {
              "description": "Master node subnet address space"
          }
      },
      "masterVmSize" : {
          "type": "string",
          "defaultValue": "Standard_D8s_v3",
          "metadata": {
              "description": "Master Node VM Type"
          }
      },
      "workerVmSize": {
          "type": "string",
          "defaultValue": "Standard_D4s_v3",
          "metadata": {
              "description": "Worker Node VM Type"
          }
      },
      "workerVmDiskSize": {
          "type" : "int",
          "defaultValue": 128,
          "minValue": 128,
          "metadata": {
              "description": "Worker Node Disk Size in GB"
          }
      },
      "workerCount": {
          "type": "int",
          "defaultValue": 3,
          "minValue": 3,
          "metadata": {
              "description": "Number of Worker Nodes"
          }
      },
      "podCidr": {
          "type": "string",
          "defaultValue": "10.128.0.0/14",
          "metadata": {
              "description": "Cidr for Pods"
          }
      },
      "serviceCidr": {
          "type": "string",
          "defaultValue": "172.30.0.0/16",
          "metadata": {
              "decription": "Cidr of service"
          }
      },
      "clusterName" : {
        "type": "string",
        "metadata": {
          "description": "Unique name for the cluster"
        }
      },
      "tags": {
          "type": "object",
          "defaultValue" : {
              "env": "Dev",
              "dept": "Ops"
          },
          "metadata": {
              "description": "Tags for resources"
          }
      },
      "apiServerVisibility": {
          "type": "string",
          "allowedValues": [
              "Private",
              "Public"
          ],
          "defaultValue": "Public",
          "metadata": {
              "description": "Api Server Visibility"
          }
      },
      "ingressVisibility": {
          "type": "string",
          "allowedValues": [
              "Private",
              "Public"
          ],
          "defaultValue": "Public",
          "metadata": {
              "description": "Ingress Visibility"
          }
      },
      "aadClientId" : {
        "type": "string",
        "metadata": {
          "description": "The Application ID of an Azure Active Directory client application"
        }
      },
      "aadObjectId": {
          "type": "string",
          "metadata": {
              "description": "The Object ID of an Azure Active Directory client application"
          }
      },
      "aadClientSecret" : {
        "type":"securestring",
        "metadata": {
          "description": "The secret of an Azure Active Directory client application"
        }
      },
      "rpObjectId": {
          "type": "String",
          "metadata": {
              "description": "The ObjectID of the Resource Provider Service Principal"
          }
      }
    },
    "variables": {
        "contribRole": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]"
    },
    "resources": [
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2020-05-01",
            "name": "[parameters('clusterVnetName')]",
            "location": "[parameters('location')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "addressSpace": {
                "addressPrefixes": [
                    "[parameters('clusterVnetCidr')]"
                    ]
                },
                "subnets": [
                {
                    "name": "master",
                    "properties": {
                        "addressPrefix": "[parameters('masterSubnetCidr')]",
                        "serviceEndpoints": [
                            {
                                "service": "Microsoft.ContainerRegistry"
                            }
                        ],
                        "privateLinkServiceNetworkPolicies": "Disabled"
                    }
                },
                {
                    "name": "worker",
                    "properties": {
                        "addressPrefix": "[parameters('workerSubnetCidr')]",
                        "serviceEndpoints": [
                            {
                                "service": "Microsoft.ContainerRegistry"
                            }
                        ]
                    }
                }]
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks/providers/roleAssignments",
            "apiVersion": "2018-09-01-preview",
            "name": "[concat(parameters('clusterVnetName'), '/Microsoft.Authorization/', guid(resourceGroup().id, deployment().name, parameters('aadObjectId')))]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('clusterVnetName'))]"
            ],
            "properties": {
                "roleDefinitionId": "[variables('contribRole')]",
                "principalId":"[parameters('aadObjectId')]"
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks/providers/roleAssignments",
            "apiVersion": "2018-09-01-preview",
            "name": "[concat(parameters('clusterVnetName'), '/Microsoft.Authorization/', guid(resourceGroup().id, deployment().name, parameters('rpObjectId')))]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('clusterVnetName'))]"
            ],
            "properties": {
                "roleDefinitionId": "[variables('contribRole')]",
                "principalId":"[parameters('rpObjectId')]"
            }
        },
        {
            "type": "Microsoft.RedHatOpenShift/OpenShiftClusters",
            "apiVersion": "2020-04-30",
            "name": "[parameters('clusterName')]",
            "location": "[parameters('location')]",
            "tags": "[parameters('tags')]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('clusterVnetName'))]"
            ],
            "properties": {
                "clusterProfile": {
                    "domain": "[parameters('domain')]",
                    "resourceGroupId": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/aro-', parameters('domain'))]",
                    "pullSecret": "[parameters('pullSecret')]"
                },
                "networkProfile": {
                    "podCidr": "[parameters('podCidr')]",
                    "serviceCidr": "[parameters('serviceCidr')]"
                },
                "servicePrincipalProfile": {
                    "clientId": "[parameters('aadClientId')]",
                    "clientSecret": "[parameters('aadClientSecret')]"
                },
                "masterProfile": {
                    "vmSize": "[parameters('masterVmSize')]",
                    "subnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('clusterVnetName'), 'master')]"
                },
                "workerProfiles": [
                    {
                        "name": "worker",
                        "vmSize": "[parameters('workerVmSize')]",
                        "diskSizeGB": "[parameters('workerVmDiskSize')]",
                        "subnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('clusterVnetName'), 'worker')]",
                        "count": "[parameters('workerCount')]"
                    }
                ],
                "apiserverProfile": {
                    "visibility": "[parameters('apiServerVisibility')]"
                },
                "ingressProfiles": [
                    {
                        "name": "default",
                        "visibility": "[parameters('ingressVisibility')]"
                    }
                ]
            }
        }
    ],
    "outputs": {
         "clusterCredentials": {
             "type": "object",
             "value": "[listCredentials(resourceId('Microsoft.RedHatOpenShift/OpenShiftClusters', parameters('clusterName')), '2020-04-30')]"
         },
         "oauthCallbackURL": {
             "type": "string",
             "value": "[concat('https://oauth-openshift.apps.', parameters('domain'), '.', parameters('location'), '.aroapp.io/oauth2callback/AAD')]"
         }
    }
}

建立 Bicep 檔案

下列範例示範針對 Azure Red Hat OpenShift 叢集設定時,您的 Azure Bicep 檔案應該如何看起來。

Bicep 檔案會定義三個 Azure 資源:

您可以在 Red Hat OpenShift 網站上找到更多 Azure Red Hat OpenShift 範本。

建立下列 Bicep 檔案,其中包含 Azure Red Hat OpenShift 叢集的定義。 下列範例顯示 Bicep 檔案在設定時的外觀。

將下列檔案儲存為 azuredeploy.bicep

@description('Location')
param location string = 'eastus'

@description('Domain Prefix')
param domain string = ''

@description('Pull secret from cloud.redhat.com. The json should be input as a string')
param pullSecret string

@description('Name of ARO vNet')
param clusterVnetName string = 'aro-vnet'

@description('ARO vNet Address Space')
param clusterVnetCidr string = '10.100.0.0/15'

@description('Worker node subnet address space')
param workerSubnetCidr string = '10.100.70.0/23'

@description('Master node subnet address space')
param masterSubnetCidr string = '10.100.76.0/24'

@description('Master Node VM Type')
param masterVmSize string = 'Standard_D8s_v3'

@description('Worker Node VM Type')
param workerVmSize string = 'Standard_D4s_v3'

@description('Worker Node Disk Size in GB')
@minValue(128)
param workerVmDiskSize int = 128

@description('Number of Worker Nodes')
@minValue(3)
param workerCount int = 3

@description('Cidr for Pods')
param podCidr string = '10.128.0.0/14'

@metadata({
  description: 'Cidr of service'
})
param serviceCidr string = '172.30.0.0/16'

@description('Unique name for the cluster')
param clusterName string

@description('Tags for resources')
param tags object = {
  env: 'Dev'
  dept: 'Ops'
}

@description('Api Server Visibility')
@allowed([
  'Private'
  'Public'
])
param apiServerVisibility string = 'Public'

@description('Ingress Visibility')
@allowed([
  'Private'
  'Public'
])
param ingressVisibility string = 'Public'

@description('The Application ID of an Azure Active Directory client application')
param aadClientId string

@description('The Object ID of an Azure Active Directory client application')
param aadObjectId string

@description('The secret of an Azure Active Directory client application')
@secure()
param aadClientSecret string

@description('The ObjectID of the Resource Provider Service Principal')
param rpObjectId string

@description('Specify if FIPS validated crypto modules are used')
@allowed([
  'Enabled'
  'Disabled'
])
param fips string = 'Disabled'

@description('Specify if master VMs are encrypted at host')
@allowed([
  'Enabled'
  'Disabled'
])
param masterEncryptionAtHost string = 'Disabled'

@description('Specify if worker VMs are encrypted at host')
@allowed([
  'Enabled'
  'Disabled'
])
param workerEncryptionAtHost string = 'Disabled'

var contributorRoleDefinitionId = resourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
var resourceGroupId = '/subscriptions/${subscription().subscriptionId}/resourceGroups/aro-${domain}-${location}'
var masterSubnetId=resourceId('Microsoft.Network/virtualNetworks/subnets', clusterVnetName, 'master')
var workerSubnetId=resourceId('Microsoft.Network/virtualNetworks/subnets', clusterVnetName, 'worker')

resource clusterVnetName_resource 'Microsoft.Network/virtualNetworks@2020-05-01' = {
  name: clusterVnetName
  location: location
  tags: tags
  properties: {
    addressSpace: {
      addressPrefixes: [
        clusterVnetCidr
      ]
    }
    subnets: [
      {
        name: 'master'
        properties: {
          addressPrefix: masterSubnetCidr
          serviceEndpoints: [
            {
              service: 'Microsoft.ContainerRegistry'
            }
          ]
          privateLinkServiceNetworkPolicies: 'Disabled'
        }
      }
      {
        name: 'worker'
        properties: {
          addressPrefix: workerSubnetCidr
          serviceEndpoints: [
            {
              service: 'Microsoft.ContainerRegistry'
            }
          ]
        }
      }
    ]
  }
}

resource clusterVnetName_Microsoft_Authorization_id_name_aadObjectId 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = {
  name: guid(aadObjectId, clusterVnetName_resource.id, contributorRoleDefinitionId)
  scope: clusterVnetName_resource
  properties: {
    roleDefinitionId: contributorRoleDefinitionId
    principalId: aadObjectId
    principalType: 'ServicePrincipal'
  }
}

resource clusterVnetName_Microsoft_Authorization_id_name_rpObjectId 'Microsoft.Authorization/roleAssignments@2020-10-01-preview' = {
  name: guid(rpObjectId, clusterVnetName_resource.id, contributorRoleDefinitionId)
  scope: clusterVnetName_resource
  properties: {
    roleDefinitionId: contributorRoleDefinitionId
    principalId: rpObjectId
    principalType: 'ServicePrincipal'
  }
}

resource clusterName_resource 'Microsoft.RedHatOpenShift/OpenShiftClusters@2023-04-01' = {
  name: clusterName
  location: location
  tags: tags
  properties: {
    clusterProfile: {
      domain: domain
      resourceGroupId: resourceGroupId
      pullSecret: pullSecret
      fipsValidatedModules: fips
    }
    networkProfile: {
      podCidr: podCidr
      serviceCidr: serviceCidr
    }
    servicePrincipalProfile: {
      clientId: aadClientId
      clientSecret: aadClientSecret
    }
    masterProfile: {
      vmSize: masterVmSize
      subnetId: masterSubnetId
      encryptionAtHost: masterEncryptionAtHost
    }
    workerProfiles: [
      {
        name: 'worker'
        vmSize: workerVmSize
        diskSizeGB: workerVmDiskSize
        subnetId: workerSubnetId
        count: workerCount
        encryptionAtHost: workerEncryptionAtHost
      }
    ]
    apiserverProfile: {
      visibility: apiServerVisibility
    }
    ingressProfiles: [
      {
        name: 'default'
        visibility: ingressVisibility
      }
    ]
  }
  dependsOn: [
    clusterVnetName_resource
  ]
}

部署azuredeploy.json範本

本節提供部署azuredeploy.json範本的相關信息。

azuredeploy.json參數

azuredeploy.json範本可用來部署 Azure Red Hat OpenShift 叢集。 下列參數為必要參數。

注意

domain針對 參數,指定將作為OpenShift主控台和API伺服器自動產生 DNS 名稱一部分的網域前置詞。 此前置詞也會用來作為用來裝載叢集 VM 之資源群組名稱的一部分。

屬性 說明 有效選項 預設值
domain 叢集的網域前置詞。 none
pullSecret 您從 Red Hat OpenShift 叢集管理員網站取得的提取密碼。
clusterName 叢集的名稱。
aadClientId Microsoft Entra 用戶端應用程式的應用程式識別碼(GUID)。
aadObjectId Microsoft Entra 用戶端應用程式之服務主體的物件識別碼(GUID)。
aadClientSecret Microsoft Entra 用戶端應用程式之服務主體的客戶端密碼,做為安全字串。
rpObjectId 資源提供者服務主體的物件標識碼(GUID)。

下列範本參數具有預設值。 您可以指定它們,但並非明確要求。

屬性 說明 有效選項 預設值
location 新 ARO 叢集的位置。 此位置可以與資源群組區域相同或不同。 eastus
clusterVnetName ARO 叢集的虛擬網路名稱。 aro-vnet
clusterVnetCidr ARO 虛擬網路的位址空間,以 無類別網路端間路由 (CIDR) 表示法表示法。 10.100.0.0/15
workerSubnetCidr 背景工作節點子網的位址空間,以 CIDR 表示法表示法表示。 10.100.70.0/23
masterSubnetCidr 控制平面節點子網的位址空間,以 CIDR 表示法表示。 10.100.76.0/24
masterVmSize 控制 平面節點的虛擬機類型/大小 Standard_D8s_v3
workerVmSize 背景工作節點的虛擬機類型/大小。 Standard_D4s_v3
workerVmDiskSize 背景工作節點的磁碟大小,以 GB 為單位。 128
workerCount 背景工作節點數目。 3
podCidr 以 CIDR 表示法表示法表示的 Pod 位址空間。 10.128.0.0/14
serviceCidr 服務地址空間,以 CIDR 表示法表示法表示。 172.30.0.0/16
tags 資源標籤的哈希表。 @{env = 'Dev'; dept = 'Ops'}
apiServerVisibility API 伺服器 (PublicPrivate) 的可見性。 公開
ingressVisibility 輸入(入口)可見性(PublicPrivate)。 公開

下列各節提供使用 PowerShell 或 Azure CLI 的指示。

PowerShell 步驟

如果您使用PowerShell,請執行下列步驟。

開始之前 - PowerShell

執行本快速入門中的命令之前,您可能需要執行 Connect-AzAccount。 在繼續之前,請先檢查您是否已連線到 Azure。 若要檢查您是否具有連線能力,請執行 Get-AzContext 以確認您是否有權存取作用中的 Azure 訂用帳戶。

注意

此範本會使用從 Red Hat OpenShift 叢集管理員網站取得的提取秘密文字。 繼續之前,請確定您已將提取密碼儲存在本機為 pull-secret.txt

$rhosPullSecret= Get-Content .\pull-secret.txt -Raw # the pull secret text that was obtained from the Red Hat OpenShift Cluster Manager website

將下列參數定義為環境變數 - PowerShell

$resourceGroup="aro-rg"	     # the new resource group for the cluster
$location="eastus"    		 # the location of the new ARO cluster
$domain="mydomain"           # the domain prefix for the cluster  
$aroClusterName="cluster"    # the name of the cluster

註冊必要的資源提供者 - PowerShell

在您的訂用帳戶中註冊下列資源提供者:Microsoft.RedHatOpenShiftMicrosoft.StorageMicrosoft.ComputeMicrosoft.Authorization

Register-AzResourceProvider -ProviderNamespace Microsoft.RedHatOpenShift
Register-AzResourceProvider -ProviderNamespace Microsoft.Compute
Register-AzResourceProvider -ProviderNamespace Microsoft.Storage
Register-AzResourceProvider -ProviderNamespace Microsoft.Authorization

建立新的資源群組 - PowerShell

New-AzResourceGroup -Name $resourceGroup -Location $location

建立新的服務主體並指派角色 - PowerShell

$suffix=Get-Random # random suffix for the Service Principal
$spDisplayName="sp-$resourceGroup-$suffix"
$azureADAppSp = New-AzADServicePrincipal -DisplayName $spDisplayName -Role Contributor

New-AzRoleAssignment -ObjectId $azureADAppSp.Id -RoleDefinitionName 'User Access Administrator' -ResourceGroupName $resourceGroup -ObjectType 'ServicePrincipal'
New-AzRoleAssignment -ObJectId $azureADAppSp.Id -RoleDefinitionName 'Contributor' -ResourceGroupName $resourceGroup -ObjectType 'ServicePrincipal'

取得服務主體密碼 - PowerShell

$aadClientSecretDigest = ConvertTo-SecureString -String $azureADAppSp.PasswordCredentials.SecretText -AsPlainText -Force

取得 OpenShift 資源提供者的服務主體 - PowerShell

$rpOpenShift =  Get-AzADServicePrincipal -DisplayName 'Azure Red Hat OpenShift RP' | Select-Object -ExpandProperty Id -Property Id -First 1

在部署叢集之前檢查參數 - PowerShell

# setup the parameters for the deployment
$templateParams = @{  
    domain = $domain
    clusterName = $aroClusterName
    location = $location
    aadClientId = $azureADAppSp.AppId
    aadObjectId = $azureADAppSp.Id
    aadClientSecret = $aadClientSecretDigest 
    rpObjectId = $rpOpenShift.Id
    pullSecret = $rhosPullSecret
}

Write-Verbose (ConvertTo-Json $templateParams) -Verbose

使用 ARM 範本部署 Azure Red Hat OpenShift 叢集 - PowerShell

New-AzResourceGroupDeployment -ResourceGroupName $resourceGroup @templateParams `
    -TemplateFile azuredeploy.json

連線至您的叢集

若要連線到新的叢集,請檢閱 連線 至 Azure Red Hat OpenShift 4 叢集的步驟

清除資源 - PowerShell

完成後,請執行下列命令來刪除您的資源群組,以及您在本教學課程中建立的所有資源。

Remove-AzResourceGroup -Name $resourceGroup -Force

Azure CLI 步驟

如果您使用 Azure CLI,請執行下列步驟。

開始之前 - Azure CLI

您可能需要先執行 az login ,再執行本快速入門中的命令。 在繼續之前,請先檢查您是否已連線到 Azure。 若要檢查您是否具有連線能力,請執行 az account list 並確認您是否有權存取作用中的 Azure 訂用帳戶。

注意

此範本會使用從 Red Hat OpenShift 叢集管理員網站取得的提取秘密文字。 繼續之前,請確定您已將秘密儲存在本機為 pull-secret.txt

PULL_SECRET=$(cat pull-secret.txt)    # the pull secret text 

將下列參數定義為環境變數 - Azure CLI

RESOURCEGROUP=aro-rg            # the new resource group for the cluster
LOCATION=eastus                 # the location of the new cluster
DOMAIN=mydomain                 # the domain prefix for the cluster
ARO_CLUSTER_NAME=aro-cluster    # the name of the cluster

註冊必要的資源提供者 - Azure CLI

在您的訂用帳戶中註冊下列資源提供者:Microsoft.RedHatOpenShiftMicrosoft.StorageMicrosoft.ComputeMicrosoft.Authorization

az provider register --namespace 'Microsoft.RedHatOpenShift' --wait
az provider register --namespace 'Microsoft.Compute' --wait
az provider register --namespace 'Microsoft.Storage' --wait
az provider register --namespace 'Microsoft.Authorization' --wait

建立新的資源群組 - Azure CLI

az group create --name $RESOURCEGROUP --location $LOCATION

為新的 Microsoft Entra 應用程式建立服務主體

  • Azure CLI
az ad sp create-for-rbac --name "sp-$RG_NAME-${RANDOM}" > app-service-principal.json
SP_CLIENT_ID=$(jq -r '.appId' app-service-principal.json)
SP_CLIENT_SECRET=$(jq -r '.password' app-service-principal.json)
SP_OBJECT_ID=$(az ad sp show --id $SP_CLIENT_ID | jq -r '.id')

將參與者角色指派給新的服務主體 - Azure CLI

az role assignment create \
    --role 'User Access Administrator' \
    --assignee-object-id $SP_OBJECT_ID \
    --scope $SCOPE \
    --assignee-principal-type 'ServicePrincipal'

az role assignment create \
    --role 'Contributor' \
    --assignee-object-id $SP_OBJECT_ID \
    --scope $SCOPE \
    --assignee-principal-type 'ServicePrincipal'

取得 OpenShift 資源提供者的服務主體物件識別碼 - Azure CLI

ARO_RP_SP_OBJECT_ID=$(az ad sp list --display-name "Azure Red Hat OpenShift RP" --query [0].id -o tsv)

部署叢集 - Azure CLI

az deployment group create \
    --name aroDeployment \
    --resource-group $RESOURCEGROUP \
    --template-file azuredeploy.bicep \
    --parameters location=$LOCATION \
    --parameters domain=$DOMAIN \
    --parameters pullSecret=$PULL_SECRET \
    --parameters clusterName=$ARO_CLUSTER_NAME \
    --parameters aadClientId=$SP_CLIENT_ID \
    --parameters aadObjectId=$SP_OBJECT_ID \
    --parameters aadClientSecret=$SP_CLIENT_SECRET \
    --parameters rpObjectId=$ARO_RP_SP_OBJECT_ID

連線 至叢集 - Azure CLI

若要連線到新的叢集,請檢閱 連線 至 Azure Red Hat OpenShift 4 叢集的步驟

清除資源 - Azure CLI

完成後,請執行下列命令來刪除您的資源群組,以及您在本教學課程中建立的所有資源。

az aro delete --resource-group $RESOURCEGROUP --name $CLUSTER

提示

有問題嗎? 在 Azure Red Hat Openshift (ARO) 存放庫中開啟問題,讓我們在 GitHub 上知道。

下一步

在本文中,您已瞭解如何使用ARM樣本和 Bicep 建立執行 OpenShift 4 的 Azure Red Hat OpenShift 叢集。

請前進到下一篇文章,以瞭解如何使用 Microsoft Entra ID 設定叢集以進行驗證。