快速入門:使用 Azure Resource Manager 範本部署 Kubernetes 叢集
適用於:Azure Stack HCI 版本 23H2
本快速入門說明如何使用 Azure Resource Manager 範本,在 AKS Arc 中部署 Kubernetes 叢集。 Azure Arc 將 Azure 管理功能延伸到 Kubernetes 叢集,提供管理不同環境的統一方法。
開始之前
本文章假設您對 Kubernetes 概念有基本瞭解。
若要部署 Resource Manager 範本,您需要部署之資源的寫入許可權,以及 Microsoft.Resources/deployments 資源類型上所有作業的存取權。 例如,若要部署虛擬機,您需要 Microsoft.Compute/virtualMachines/write 和 Microsoft.Resources/deployments/* 許可權。 如需角色與權限的清單,請參閱 Azure 內建角色。
必要條件
- 具備有效訂用帳戶的 Azure 帳戶。
- Azure Stack HCI 23H2 叢集。
- 最新的 Azure CLI 版本。
步驟 1:準備您的 Azure 帳戶
登入 Azure:開啟終端機或命令提示字元,並使用 Azure CLI 登入您的 Azure 帳戶:
az login
設定您的訂用帳戶:以您的訂用帳戶識別碼取代
<your-subscription-id>
:az account set --subscription "<your-subscription-id>"
步驟 2:使用 Azure CLI 建立 SSH 金鑰組
az sshkey create --name "mySSHKey" --resource-group "myResourceGroup"
或者,使用 ssh-keygen 建立 SSH 金鑰組:
ssh-keygen -t rsa -b 4096
若要部署範本,您必須從 SSH 配對提供公鑰。 若要擷取公鑰,請使用 az sshkey show
命令:
az sshkey show --name "mySSHKey" --resource-group "myResourceGroup" --query "publicKey"
根據預設,SSH 金鑰檔案會在 ~/.ssh 目錄中建立。 az sshkey create
執行 或 ssh-keygen
命令,以使用相同的名稱覆寫任何現有的 SSH 金鑰組。
如需建立 SSH 金鑰的詳細資訊,請參閱在 Azure 中建立及管理驗證的 SSH 金鑰。
步驟 3:檢閱範本
本快速入門中使用的範本來自 Azure 快速入門範本存放庫:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"provisionedClusterName": {
"type": "string",
"defaultValue": "aksarc-armcluster",
"metadata": {
"description": "The name of the AKS Arc Cluster resource."
}
},
"location": {
"type": "string",
"defaultValue": "eastus",
"metadata": {
"description": "The location of the AKS Arc Cluster resource."
}
},
"resourceTags": {
"type": "object",
"defaultValue": {}
},
"sshRSAPublicKey": {
"type": "string",
"metadata": {
"description": "Configure all linux machines with the SSH RSA public key string. Your key should include three parts, for example 'ssh-rsa AAAAB...snip...UcyupgH '"
}
},
"enableAHUB": {
"type": "string",
"defaultValue": "NotApplicable",
"metadata": {
"description": "Azure Hybrid Benefit for Windows Server licenses. NotApplicable, True, False."
}
},
"agentName": {
"type": "string",
"defaultValue": "nodepool",
"metadata": {
"description": "The name of the node pool."
}
},
"agentVMSize": {
"type": "string",
"defaultValue": "Standard_A4_v2",
"metadata": {
"description": "The VM size for node pools."
}
},
"agentCount": {
"type": "int",
"defaultValue": 1,
"minValue": 1,
"maxValue": 50,
"metadata": {
"description": "The number of nodes for the cluster."
}
},
"agentOsType": {
"type": "string",
"defaultValue": "Linux",
"metadata": {
"description": "The OS Type for the agent pool. Values are Linux and Windows."
}
},
"loadBalancerCount": {
"type": "int",
"defaultValue": 0,
"metadata": {
"description": "The number of load balancers."
}
},
"kubernetesVersion": {
"type": "string",
"metadata": {
"description": "The version of Kubernetes."
}
},
"controlPlaneNodeCount": {
"type": "int",
"defaultValue": 1,
"minValue": 1,
"maxValue": 5,
"metadata": {
"description": "The number of control plane nodes for the cluster."
}
},
"controlPlaneIp": {
"type": "string",
"defaultValue": "<default_value>",
"metadata": {
"description": "Control plane IP address."
}
},
"controlPlaneVMSize": {
"type": "string",
"defaultValue": "Standard_A4_v2",
"metadata": {
"description": "The VM size for control plane."
}
},
"vnetSubnetIds": {
"type": "array",
"metadata": {
"description": "List of subnet Ids for the AKS cluster."
}
},
"podCidr": {
"type": "string",
"defaultValue": "10.244.0.0/16",
"metadata": {
"description": "The VM size for control plane."
}
},
"networkPolicy": {
"type": "string",
"defaultValue": "calico",
"metadata": {
"description": "Network policy to use for Kubernetes pods. Only options supported is calico."
}
},
"customLocation": {
"type": "string",
"metadata": {
"description": "Fully qualified custom location resource Id."
}
}
},
"resources": [
{
"apiVersion": "2024-01-01",
"type": "Microsoft.Kubernetes/ConnectedClusters",
"kind": "ProvisionedCluster",
"location": "[parameters('location')]",
"name": "[parameters('provisionedClusterName')]",
"tags": "[parameters('resourceTags')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"agentPublicKeyCertificate":"" ,
"aadProfile": {
"enableAzureRBAC": false
}
}
},
{
"apiVersion": "2024-01-01",
"type": "microsoft.hybridcontainerservice/provisionedclusterinstances",
"name": "default",
"scope": "[concat('Microsoft.Kubernetes/ConnectedClusters', '/', parameters('provisionedClusterName'))]",
"dependsOn": [
"[resourceId('Microsoft.Kubernetes/ConnectedClusters', parameters('provisionedClusterName'))]"
],
"properties": {
"agentPoolProfiles": [
{
"count": "[parameters('agentCount')]",
"name":"[parameters('agentName')]",
"osType": "[parameters('agentOsType')]",
"vmSize": "[parameters('agentVMSize')]"
}
],
"cloudProviderProfile": {
"infraNetworkProfile": {
"vnetSubnetIds": "[parameters('vnetSubnetIds')]"
}
},
"controlPlane": {
"count": "[parameters('controlPlaneNodeCount')]",
"controlPlaneEndpoint": {
"hostIP": "[parameters('controlPlaneIp')]"
},
"vmSize": "[parameters('controlPlaneVMSize')]"
},
"licenseProfile": {
"azureHybridBenefit": "[parameters('enableAHUB')]"
},
"kubernetesVersion": "[parameters('kubernetesVersion')]",
"linuxProfile": {
"ssh": {
"publicKeys": [
{
"keyData": "[parameters('sshRSAPublicKey')]"
}
]
}
},
"networkProfile": {
"loadBalancerProfile": {
"count": "[parameters('loadBalancerCount')]"
},
"networkPolicy": "[parameters('networkPolicy')]",
"podCidr": "[parameters('podCidr')]"
},
"storageProfile": {
"nfsCsiDriver": {
"enabled": false
},
"smbCsiDriver": {
"enabled": false
}
}
},
"extendedLocation": {
"name": "[parameters('customLocation')]",
"type": "CustomLocation"
}
}
]
}
步驟 4:部署範本
若要部署範本,請執行下列命令來部署 Kubernetes 叢集:
az deployment group create \
--name "<deployment-name>" \
--resource-group "<resource-group-name>" \
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.kubernetes/aks-arc/azuredeploy.json" \
--parameters provisionedClusterName="<cluster-name> location="eastus" sshRSApublicKey="" etc..."
建立叢集需要幾分鐘的時間。 請等到叢集成功部署後,再移至下一個步驟。
步驟 5:確認部署
部署完成後,請使用下列命令來確認 Kubernetes 叢集已啟動並執行:
az aksarc show --resource-group "<resource-group-name>" --name "<cluster-name>" --output table
步驟 6:連線到叢集
若要連線到叢集,請執行
az connectedk8s proxy
命令。 命令會在用戶端電腦上下載並執行 Proxy 二進位檔,並擷取與叢集相關聯的 kubeconfig 檔案:az connectedk8s proxy --name <cluster name> -g <resource group>
或者,使用 Kubernetes 命令行用戶端 kubectl。 如果您使用 Azure Cloud Shell,則已安裝 kubectl。 若要在本機安裝和執行 kubectl ,請執行
az aksarc install-cli
命令。設定 kubectl 以使用
az aksarc get-credentials
命令連線到 Kubernetes 叢集。 此命令會下載認證,並設定 Kubernetes CLI 以使用認證:az aksarc get-credentials --resource-group "<resource-group-name>" --name "<cluster-name>"
使用
kubectl get
命令確認叢集的連線。 這個指令會傳回叢集節點的清單:kubectl get nodes -A --kubeconfig .\<path to kubecofig>
下列範例輸出顯示先前步驟中建立的三個節點。 確定節點的狀態為就緒:
NAME STATUS ROLES AGE VERSION aks-agentpool-27442051-vmss000000 Ready agent 10m v1.27.7 aks-agentpool-27442051-vmss000001 Ready agent 10m v1.27.7 aks-agentpool-27442051-vmss000002 Ready agent 11m v1.27.7
範本資源
connectedClusters
名稱 | 描述 | 值 |
---|---|---|
type |
資源類型。 | Microsoft.Kubernetes/ConnectedClusters |
apiVersion |
資源 API 版本。 | 2024-01-01 |
name |
資源名稱。 | 需要字串 () 字元限制:1-63 有效字元:英數位元、底線和連字元。 以英數字元開頭及結尾。 |
location |
資源所在的地理位置。 | 需要字串 () 。 |
tags |
資源標籤。 | 標記名稱和值的字典。 請參閱 範本中的標記。 |
extendedLocation |
虛擬機的擴充位置。 | ExtendedLocation |
identity |
如果已設定,則為已連線叢集的身分識別。 | |
properties |
已連線叢集的屬性。 |
ProvisionedClusterInstances
名稱 | 描述 | 值 |
---|---|---|
type |
資源類型 | microsoft.hybridcontainerservice/provisionedclusterinstances |
apiVersion |
資源 API 版本 | 2024-01-01 |
name |
資源名稱 | 需要字串 () 。 請勿從 預設變更此值。 |
properties |
已連線叢集的屬性。 | |
extendedLocation |
叢集的擴充位置。 | ExtendedLocation |
ExtendedLocation
名稱 | 描述 | 值 |
---|---|---|
name |
擴充位置的標識碼。 | 字串 |
type |
擴充位置的類型。 | CustomLocation |
下一步
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應