快速入门:使用 Azure 资源管理器 模板部署 Kubernetes 群集
适用于:Azure 本地版本 23H2
本快速入门介绍如何使用 Azure 资源管理器 (ARM) 模板在 AKS Arc 中部署 Kubernetes 群集。 Azure Arc 将 Azure 管理功能扩展到任何位置的 Kubernetes 群集,提供统一管理不同环境的方法。
开始之前
本文假定你对 Kubernetes 概念有基本的了解。
若要部署 ARM 模板,需要对要部署的资源具有写入权限,并且需要对 Microsoft.Resources/deployments 资源类型的所有操作具有访问权限。 例如,若要部署虚拟机,需要 Microsoft.Compute/virtualMachines/write 和 Microsoft.Resources/deployments/* 权限。 有关角色和权限的列表,请参阅 Azure 内置角色。
先决条件
- 具有活动订阅的 Azure 帐户。
- Azure 本地版本 23H2 群集。
- 最新的 Azure CLI 版本。
步骤 1:准备 Azure 帐户
登录到 Azure:打开终端或命令提示符,并使用 Azure CLI 登录到 Azure 帐户:
az login
设置订阅:替换为
<your-subscription-id>
订阅 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:查看模板
将 AKSArc 存储库中的模板和参数文件下载到本地计算机。 查看所有默认值并确保它们正确无误。
步骤 4:部署模板
若要部署 Kubernetes 群集,请运行以下命令:
az deployment group create \
--name "<deployment-name>" \
--resource-group "<resource-group-name>" \
--template-file "azuredeploy.json" \
--parameters "azuredeploy.parameters.json"
创建群集需要几分钟时间。 等待群集成功部署,然后转到下一步骤。
步骤 5:验证部署
部署完成后,使用以下命令验证 Kubernetes 群集是否已启动并运行:
az aksarc show --resource-group "<resource-group-name>" --name "<cluster-name>" --output table
步骤 6:连接到群集
若要连接到群集,请运行
az connectedk8s 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>
以下示例输出显示在上一步骤中创建的三个节点。 确保节点状态为 Ready:
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
步骤 7:使用 Azure 资源管理器模板部署节点池(可选)
与步骤 3 类似,从 AKSArc 存储库中下载节点池模板和参数 并查看默认值。
使用 Azure CLI 部署模板并验证结果(可选)
查看并应用模板。 此过程需要几分钟才能完成。 可以使用 Azure CLI 验证是否已成功创建节点池:
az deployment group create \
--name "<deployment-name>" \
--resource-group "<resource-group-name>" \
--template-file "azuredeploy.json" \
--parameters "azuredeploy.parameters.json"
az aksarc nodepool show --cluster-name "<cluster-name>" --resource-group "<resource-group-name>" --name "<nodepool-name>"
模板资源
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 |
扩展位置的 ID。 | string |
type |
扩展位置的类型。 | CustomLocation |