你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

快速入门:使用 Azure 资源管理器模板(ARM 模板)部署 Azure Nexus Kubernetes 群集

  • 使用 Azure 资源管理器模板部署 Azure Nexus Kubernetes 群集。

本快速入门介绍如何使用 Azure 资源管理器模板(ARM 模板)创建 Azure Nexus Kubernetes 群集。

Azure 资源管理器模板是一个 JavaScript 对象表示法(JSON)文件,用于定义项目的基础结构和配置。 模板使用声明性语法。 你可以在不编写用于创建部署的编程命令序列的情况下,描述预期部署。

先决条件

如果没有 Azure 帐户,请在开始前创建一个免费帐户

  • 安装必需的 Azure CLI 扩展的最新版本。

  • 本文需要 2.61.0 或更高版本的 Azure CLI。 如果使用 Azure Cloud Shell,则最新版本已安装。

  • 如果你有多个 Azure 订阅,请使用 az account 命令选择应在其中计收资源费用的相应订阅 ID。

  • 有关支持的 VM SKU 列表,请参阅参考部分中的 VM SKU 表。

  • 有关受支持的 Kubernetes 版本的列表,请参阅受支持的 Kubernetes 版本

  • 使用 az group create 命令创建资源组。 Azure 资源组是用于部署和管理 Azure 资源的逻辑组。 创建资源组时,系统会提示你指定一个位置。 此位置是资源组元数据的存储位置,也是资源在 Azure 中运行的位置(如果你在创建资源期间未指定其他区域)。 以下示例在“eastus”位置创建名为“myResourceGroup”的资源组。

    az group create --name myResourceGroup --___location eastus
    

    以下输出示例类似于成功创建资源组:

    {
      "id": "/subscriptions/<guid>/resourceGroups/myResourceGroup",
      "___location": "eastus",
      "managedBy": null,
      "name": "myResourceGroup",
      "properties": {
        "provisioningState": "Succeeded"
      },
      "tags": null
    }
    
  • 若要部署 Bicep 文件或 ARM 模板,需要对要部署的资源具有写入权限,并且需要对 Microsoft.Resources/deployments 资源类型的所有操作具有访问权限。 例如,若要部署群集,需要 Microsoft.NetworkCloud/kubernetesclusters/write 和 Microsoft.Resources/deployments/* 权限。 有关角色和权限的列表,请参阅 Azure 内置角色

  • 需要 Azure Operator Nexus 群集的 custom ___location 资源 ID。

  • 需要根据特定的工作负载要求创建各种网络,并且必须具有适用于工作负载的相应 IP 地址。 为确保顺利实施,建议咨询相关支持团队以获取帮助。

  • 本快速入门假设读者基本了解 Kubernetes 的概念。 有关详细信息,请参阅 Azure Kubernetes 服务 (AKS) 的 Kubernetes 核心概念

查看模板

在部署 Kubernetes 模板之前,让我们查看内容以了解其结构。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "kubernetesClusterName": {
        "type": "string",
        "metadata": {
          "description": "The name of Nexus Kubernetes cluster"
        }
      },
      "___location": {
        "type": "string",
        "metadata": {
          "description": "The Azure region where the cluster is to be deployed"
        },
        "defaultValue": "[resourceGroup().___location]"
      },
      "extendedLocation": {
        "type": "string",
        "metadata": {
          "description": "The custom ___location of the Nexus instance"
        },
        "defaultValue": ""
      },
      "tags": {
        "type": "object",
        "metadata": {
          "description": "The metadata tags to be associated with the cluster resource"
        },
        "defaultValue": {}
      },
      "adminUsername": {
        "type": "string",
        "metadata": {
          "description": "The username for the administrative account on the cluster"
        },
        "defaultValue": "azureuser"
      },
      "adminGroupObjectIds": {
        "type": "array",
        "metadata": {
          "description": "The object IDs of Azure Active Directory (AAD) groups that will have administrative access to the cluster"
        },
        "defaultValue": []
      },
      "cniNetworkId": {
        "type": "string",
        "metadata": {
          "description": "The Azure Resource Manager (ARM) id of the network to be used as the Container Networking Interface (CNI) network"
        }
      },
      "cloudServicesNetworkId": {
        "type": "string",
        "metadata": {
          "description": "The ARM id of the network to be used for cloud services network"
        }
      },
      "podCidrs": {
        "type": "array",
        "metadata": {
          "description": "The CIDR blocks used for Nexus Kubernetes PODs in the cluster"
        },
        "defaultValue": ["10.244.0.0/16"]
      },
      "serviceCidrs": {
        "type": "array",
        "metadata": {
          "description": "The CIDR blocks used for k8s service in the cluster"
        },
        "defaultValue": ["10.96.0.0/16"]
      },
      "dnsServiceIp": {
        "type": "string",
        "metadata": {
          "description": "The IP address of the DNS service in the cluster"
        },
        "defaultValue": "10.96.0.10"
      },
      "agentPoolL2Networks": {
        "type": "array",
        "metadata": {
          "description": "The Layer 2 networks associated with the initial agent pool"
        },
        "defaultValue": []
        /*
          {
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN"
          }
        */
      },
      "agentPoolL3Networks": {
        "type": "array",
        "metadata": {
          "description": "The Layer 3 networks associated with the initial agent pool"
        },
        "defaultValue": []
        /*
          {
            "ipamEnabled": "True/False",
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN|IPVLAN"
          }
        */
      },
      "agentPoolTrunkedNetworks": {
        "type": "array",
        "metadata": {
          "description": "The trunked networks associated with the initial agent pool"
        },
        "defaultValue": []
        /*
          {
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN"
          }
        */
      },
      "l2Networks": {
        "type": "array",
        "metadata": {
          "description": "The Layer 2 networks associated with the cluster"
        },
        "defaultValue": []
        /*
          {
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN"
          }
        */
      },
      "l3Networks": {
        "type": "array",
        "metadata": {
          "description": "The Layer 3 networks associated with the cluster"
        },
        "defaultValue": []
        /*
          {
            "ipamEnabled": "True/False",
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN|IPVLAN"
          }
        */
      },
      "trunkedNetworks": {
        "type": "array",
        "metadata": {
          "description": "The trunked networks associated with the cluster"
        },
        "defaultValue": []
        /*
          {
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN"
          }
        */
      },
      "ipAddressPools": {
        "type": "array",
        "metadata": {
          "description": "The LoadBalancer IP address pools associated with the cluster"
        },
        "defaultValue": []
        /*
          {
            "addresses": [
              "string"
            ],
            "autoAssign": "True/False",
            "name": "sting",
            "onlyUseHostIps": "True/False"
          }
        */
      },
      "fabricPeeringEnabled": {
        "type": "string",
        "metadata": {
          "description": "The indicator to specify if the load balancer peers with the network fabric."
        },
        "defaultValue": "True"
      },
      "bgpAdvertisements": {
        "type": "array",
        "metadata": {
          "description": "The association of IP address pools to the communities and peers, allowing for announcement of IPs."
        },
        "defaultValue": []
        /*
          {
            "advertiseToFabric": "True/False",
            "communities": [
              "string"
            ],
            "ipAddressPools": [
              "string"
            ],
            "pools": [
              "string"
            ]
          }
        */
      },
      "bgpPeers": {
        "type": "array",
        "metadata": {
          "description": "The list of additional BgpPeer entities that the Kubernetes cluster will peer with. All peering must be explicitly defined."
        },
        "defaultValue": []
        /*
          {
            "bfdEnabled": "True/False",
            "bgpMultiHop": "True/False",
            "myAsn": 0-4294967295,
            "name": "string",
            "password": "string",
            "peerAddress": "string",
            "peerPort": 179
          }
        */
      },
      "kubernetesVersion": {
        "type": "string",
        "metadata": {
          "description": "The version of Kubernetes to be used in the Nexus Kubernetes cluster"
        },
        "defaultValue": "v1.27.1"
      },
      "controlPlaneCount": {
        "type": "int",
        "metadata": {
          "description": "The number of control plane nodes to be deployed in the cluster"
        },
        "defaultValue": 1
      },
      "controlPlaneZones": {
        "type": "array",
        "metadata": {
          "description": "The zones/racks used for placement of the control plane nodes"
        },
        "defaultValue": []
        /* array of strings Example: ["1", "2", "3"] */
      },
      "agentPoolZones": {
        "type": "array",
        "metadata": {
          "description": "The zones/racks used for placement of the agent pool nodes"
        },
        "defaultValue": []
        /* array of strings Example: ["1", "2", "3"] */
      },
      "controlPlaneVmSkuName": {
        "type": "string",
        "metadata": {
          "description": "The size of the control plane nodes"
        },
        "defaultValue": "NC_G6_28_v1"
      },
      "systemPoolNodeCount": {
        "type": "int",
        "metadata": {
          "description": "The number of worker nodes to be deployed in the initial agent pool"
        },
        "defaultValue": 1
      },
      "workerVmSkuName": {
        "type": "string",
        "metadata": {
          "description": "The size of the worker nodes"
        },
        "defaultValue": "NC_P10_56_v1"
      },
      "initialPoolAgentOptions": {
        "type": "object",
        "metadata": {
          "description": "The configurations for the initial agent pool"
        },
        "defaultValue": {}
        /*
          "hugepagesCount": int,
          "hugepagesSize": "2M/1G"
        */
      },
      "sshPublicKeys": {
        "type": "array",
        "metadata": {
          "description": "The cluster wide SSH public key that will be associated with the given user for secure remote login"
        },
        "defaultValue": []
        /*
          {
            "keyData": "ssh-rsa AAAAA...."
          },
          {
            "keyData": "ssh-rsa BBBBB...."
          }
        */
      },
      "controlPlaneSshKeys": {
        "type": "array",
        "metadata": {
          "description": "The control plane SSH public key that will be associated with the given user for secure remote login"
        },
        "defaultValue": []
        /*
          {
            "keyData": "ssh-rsa AAAAA...."
          },
          {
            "keyData": "ssh-rsa BBBBB...."
          }
        */
      },
      "agentPoolSshKeys": {
        "type": "array",
        "metadata": {
          "description": "The agent pool SSH public key that will be associated with the given user for secure remote login"
        },
        "defaultValue": []
        /*
          {
            "keyData": "ssh-rsa AAAAA...."
          },
          {
            "keyData": "ssh-rsa BBBBB...."
          }
        */
      },
      "labels": {
        "type": "array",
        "metadata": {
          "description": "The labels to assign to the nodes in the cluster for identification and organization"
        },
        "defaultValue": []
        /*
          {
            "key": "string",
            "value": "string"
          }
        */
      },
      "taints": {
        "type": "array",
        "metadata": {
          "description": "The taints to apply to the nodes in the cluster to restrict which pods can be scheduled on them"
        },
        "defaultValue": []
        /*
          {
            "key": "string",
            "value": "string:NoSchedule|PreferNoSchedule|NoExecute"
          }
        */
      }
    },
    "resources": [
      {
        "type": "Microsoft.NetworkCloud/kubernetesClusters",
        "apiVersion": "2025-02-01",
        "name": "[parameters('kubernetesClusterName')]",
        "___location": "[parameters('___location')]",
        "tags": "[parameters('tags')]",
        "extendedLocation": {
          "name": "[parameters('extendedLocation')]",
          "type": "CustomLocation"
        },
        "properties": {
          "kubernetesVersion": "[parameters('kubernetesVersion')]",
          "managedResourceGroupConfiguration": {
            "name": "[concat(uniqueString(resourceGroup().name), '-', parameters('kubernetesClusterName'))]",
            "___location": "[parameters('___location')]"
          },
          "aadConfiguration": {
            "adminGroupObjectIds": "[parameters('adminGroupObjectIds')]"
          },
          "administratorConfiguration": {
            "adminUsername": "[parameters('adminUsername')]",
            "sshPublicKeys": "[if(empty(parameters('sshPublicKeys')), createArray(), parameters('sshPublicKeys'))]"
          },
          "initialAgentPoolConfigurations": [
            {
              "name": "[concat(parameters('kubernetesClusterName'), '-nodepool-1')]",
              "administratorConfiguration": {
                "adminUsername": "[parameters('adminUsername')]",
                "sshPublicKeys": "[if(empty(parameters('agentPoolSshKeys')), createArray(), parameters('agentPoolSshKeys'))]"
              },
              "count": "[parameters('systemPoolNodeCount')]",
              "vmSkuName": "[parameters('workerVmSkuName')]",
              "mode": "System",
              "labels": "[if(empty(parameters('labels')), json('null'), parameters('labels'))]",
              "taints": "[if(empty(parameters('taints')), json('null'), parameters('taints'))]",
              "agentOptions": "[if(empty(parameters('initialPoolAgentOptions')), json('null'), parameters('initialPoolAgentOptions'))]",
              "attachedNetworkConfiguration": {
                "l2Networks": "[if(empty(parameters('agentPoolL2Networks')), json('null'), parameters('agentPoolL2Networks'))]",
                "l3Networks": "[if(empty(parameters('agentPoolL3Networks')), json('null'), parameters('agentPoolL3Networks'))]",
                "trunkedNetworks": "[if(empty(parameters('agentPoolTrunkedNetworks')), json('null'), parameters('agentPoolTrunkedNetworks'))]"
              },
              "availabilityZones": "[if(empty(parameters('agentPoolZones')), json('null'), parameters('agentPoolZones'))]",
              "upgradeSettings": {
                "maxSurge": "1"
              }
            }
          ],
          "controlPlaneNodeConfiguration": {
            "administratorConfiguration": {
              "adminUsername": "[parameters('adminUsername')]",
              "sshPublicKeys": "[if(empty(parameters('controlPlaneSshKeys')), createArray(), parameters('controlPlaneSshKeys'))]"
            },
            "count": "[parameters('controlPlaneCount')]",
            "vmSkuName": "[parameters('controlPlaneVmSkuName')]",
            "availabilityZones": "[if(empty(parameters('controlPlaneZones')), json('null'), parameters('controlPlaneZones'))]"
          },
          "networkConfiguration": {
            "cniNetworkId": "[parameters('cniNetworkId')]",
            "cloudServicesNetworkId": "[parameters('cloudServicesNetworkId')]",
            "dnsServiceIp": "[parameters('dnsServiceIp')]",
            "podCidrs": "[parameters('podCidrs')]",
            "serviceCidrs": "[parameters('serviceCidrs')]",
            "attachedNetworkConfiguration": {
              "l2Networks": "[if(empty(parameters('l2Networks')), json('null'), parameters('l2Networks'))]",
              "l3Networks": "[if(empty(parameters('l3Networks')), json('null'), parameters('l3Networks'))]",
              "trunkedNetworks": "[if(empty(parameters('trunkedNetworks')), json('null'), parameters('trunkedNetworks'))]"
            },
            "bgpServiceLoadBalancerConfiguration": {
              "ipAddressPools": "[if(empty(parameters('ipAddressPools')), json('null'), parameters('ipAddressPools'))]",
              "fabricPeeringEnabled": "[if(empty(parameters('fabricPeeringEnabled')), json('null'), parameters('fabricPeeringEnabled'))]",
              "bgpAdvertisements": "[if(empty(parameters('bgpAdvertisements')), json('null'), parameters('bgpAdvertisements'))]",
              "bgpPeers": "[if(empty(parameters('bgpPeers')), json('null'), parameters('bgpPeers'))]"
            }
          }
        }
      }
    ]
  }

阅读文章并保存名为 kubernetes-deploy.json 的模板文件后,继续按下一节所述部署模板。

部署模板

  1. 创建一个名为 kubernetes-deploy-parameters.json 的文件,并以 JSON 格式添加所需参数。 可以使用以下示例作为起点。 将值替换成自己的值。
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "kubernetesClusterName":{
      "value": "myNexusK8sCluster"
    },
    "adminGroupObjectIds": {
      "value": [
        "00000000-0000-0000-0000-000000000000"
      ]
    },
    "cniNetworkId": {
      "value": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.NetworkCloud/l3Networks/<l3Network-name>"
    },
    "cloudServicesNetworkId": {
      "value": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.NetworkCloud/cloudServicesNetworks/<csn-name>"
    },
    "extendedLocation": {
      "value": "/subscriptions/<subscription_id>/resourceGroups/<managed_resource_group>/providers/microsoft.extendedlocation/customlocations/<custom-___location-name>"
    },
    "___location": {
      "value": "eastus"
    },
    "sshPublicKeys": {
      "value": [
        {
          "keyData": "ssh-rsa AAAAA...."
        },
        {
          "keyData": "ssh-rsa BBBBB...."
        }
      ]
    }
  }
}
  1. 部署模板。
    az deployment group create \
      --resource-group myResourceGroup \
      --template-file kubernetes-deploy.json \
      --parameters @kubernetes-deploy-parameters.json

如果没有足够的容量来部署请求的群集节点,则会显示一条错误消息。 但是,此消息不提供任何有关可用容量的详细信息。 它会指出群集创建由于容量不足而无法继续。

注释

容量计算考虑到了整个平台群集,而不是仅限于单个机架。 因此,如果在容量不足的某个区域(这里,一个机架等于一个区域)中创建代理池,但另一个区域具有足够的容量,则群集创建将继续,但最终会超时。仅当在创建群集或代理池期间未指定特定区域时,这种容量检查方法才有意义。

查看已部署的资源

部署完成后,可以使用 CLI 或 Azure 门户查看资源。

若要查看 myNexusK8sCluster 资源组中 myResourceGroup 群集的详细信息,请执行以下 Azure CLI 命令:

az networkcloud kubernetescluster show \
  --name myNexusK8sCluster \
  --resource-group myResourceGroup

此外,若要获取与 myNexusK8sCluster 资源组中的 myResourceGroup 群集关联的代理池名称列表,可以使用以下 Azure CLI 命令。

az networkcloud kubernetescluster agentpool list \
  --kubernetes-cluster-name myNexusK8sCluster \
  --resource-group myResourceGroup \
  --output table

连接至群集

请注意,成功创建 Nexus Kubernetes 群集并将其连接到 Azure Arc 后,可以使用群集连接功能轻松连接到它。 通过群集连接,可以从任意位置安全地访问和管理群集,方便执行交互式开发、调试和群集管理任务。

有关可用选项的更多详细信息,请参阅连接到 Azure Operator Nexus Kubernetes 群集

注释

创建 Nexus Kubernetes 群集时,Nexus 会自动创建专用于存储群集资源的托管资源组,在此组中,会建立 Arc 连接的群集资源。

要访问群集,需要设置群集连接 kubeconfig。 使用相关 Microsoft Entra 实体登录到 Azure CLI 后,可以获取从任意位置(甚至在群集周围的防火墙以外)与群集通信所需的 kubeconfig

  1. 设置 CLUSTER_NAMERESOURCE_GROUPSUBSCRIPTION_ID 变量。

    CLUSTER_NAME="myNexusK8sCluster"
    RESOURCE_GROUP="myResourceGroup"
    SUBSCRIPTION_ID=<set the correct subscription_id>
    
  2. 查询具有 az 的托管资源组并将其存储在 MANAGED_RESOURCE_GROUP

     az account set -s $SUBSCRIPTION_ID
     MANAGED_RESOURCE_GROUP=$(az networkcloud kubernetescluster show -n $CLUSTER_NAME -g $RESOURCE_GROUP --output tsv --query managedResourceGroupConfiguration.name)
    
  3. 以下命令会启动 connectedk8s 代理,你可以通过该代理连接到指定 Nexus Kubernetes 群集的 Kubernetes API 服务器。

    az connectedk8s proxy -n $CLUSTER_NAME  -g $MANAGED_RESOURCE_GROUP &
    
  4. 使用 kubectl 将请求发送到群集:

    kubectl get pods -A
    

    现在应会看到来自群集的响应,其中包含所有节点的列表。

注释

如果看到错误消息“无法将访问令牌发布到客户端代理,无法连接到 MSI”,则可能需要执行 az login 以使用 Azure 重新进行身份验证。

添加代理池

在上一步骤中创建的群集包含单个节点池。 让我们使用 ARM 模板添加第二个代理池。 以下示例创建一个名为 myNexusK8sCluster-nodepool-2 的代理池:

  1. 查看模板。

在添加代理池模板之前,让我们查看内容以了解其结构。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "kubernetesClusterName": {
        "type": "string",
        "metadata": {
          "description": "The name of Nexus Kubernetes cluster"
        }
      },
      "___location": {
        "type": "string",
        "defaultValue": "[resourceGroup().___location]",
        "metadata": {
          "description": "The Azure region where the cluster is to be deployed"
        }
      },
      "extendedLocation": {
        "type": "string",
        "metadata": {
          "description": "The custom ___location of the Nexus instance"
        }
      },
      "adminUsername": {
        "type": "string",
        "defaultValue": "azureuser",
        "metadata": {
          "description": "The username for the administrative account on the cluster"
        }
      },
      "agentPoolSshKeys": {
        "type": "array",
        "metadata": {
          "description": "The agent pool SSH public key that will be associated with the given user for secure remote login"
        },
        "defaultValue": []
        /*
          {
            "keyData": "ssh-rsa AAAAA...."
          },
          {
            "keyData": "ssh-rsa BBBBB...."
          }
        */
      },
      "agentPoolNodeCount": {
        "type": "int",
        "defaultValue": 1,
        "metadata": {
          "description": "Number of nodes in the agent pool"
        }
      },
      "agentPoolName": {
        "type": "string",
        "defaultValue": "nodepool-2",
        "metadata": {
          "description": "Agent pool name"
        }
      },
      "agentVmSku": {
        "type": "string",
        "defaultValue": "NC_P10_56_v1",
        "metadata": {
          "description": "VM size of the agent nodes"
        }
      },
      "agentPoolZones": {
        "type": "array",
        "defaultValue": [],
        "metadata": {
          "description": "The zones/racks used for placement of the agent pool nodes"
        }
        /* array of strings Example: ["1", "2", "3"] */
      },
      "agentPoolMode": {
        "type": "string",
        "defaultValue": "User",
        "metadata": {
          "description": "Agent pool mode"
        }
      },
      "agentOptions": {
        "type": "object",
        "defaultValue": {},
        "metadata": {
          "description": "The configurations for the initial agent pool"
        }
        /*
          "hugepagesCount": int,
          "hugepagesSize": "2M/1G"
        */
      },
      "labels": {
        "type": "array",
        "defaultValue": [],
        "metadata": {
          "description": "The labels to assign to the nodes in the cluster for identification and organization"
        }
        /*
          {
            "key": "string",
            "value": "string"
          }
        */
      },
      "taints": {
        "type": "array",
        "defaultValue": [],
        "metadata": {
          "description": "The taints to apply to the nodes in the cluster to restrict which pods can be scheduled on them"
        }
        /*
          {
            "key": "string",
            "value": "string:NoSchedule|PreferNoSchedule|NoExecute"
          }
        */
      },
      "l2Networks": {
        "type": "array",
        "defaultValue": [],
        "metadata": {
          "description": "The Layer 2 networks to connect to the agent pool"
        }
        /*
          {
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN|IPVLAN"
          }
        */
      },
      "l3Networks": {
        "type": "array",
        "defaultValue": [],
        "metadata": {
          "description": "The Layer 3 networks to connect to the agent pool"
        }
        /*
          {
            "ipamEnabled": "True/False",
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN|IPVLAN"
          }
        */
      },
      "trunkedNetworks": {
        "type": "array",
        "defaultValue": [],
        "metadata": {
          "description": "The trunked networks to connect to the agent pool"
        }
        /*
          {
            "networkId": "string",
            "pluginType": "SRIOV|DPDK|OSDevice|MACVLAN|IPVLAN"
          }
        */
      }
    },
    "resources": [
      {
        "type": "Microsoft.NetworkCloud/kubernetesClusters/agentpools",
        "apiVersion": "2025-02-01",
        "name": "[concat(parameters('kubernetesClusterName'), '/', parameters('kubernetesClusterName'), '-', parameters('agentPoolName'))]",
        "___location": "[parameters('___location')]",
        "extendedLocation": {
          "name": "[parameters('extendedLocation')]",
          "type": "CustomLocation"
        },
        "properties": {
          "administratorConfiguration": {
            "adminUsername": "[parameters('adminUsername')]",
            "sshPublicKeys": "[if(empty(parameters('agentPoolSshKeys')), json('null'), parameters('agentPoolSshKeys'))]"
          },
          "count": "[parameters('agentPoolNodeCount')]",
          "mode": "[parameters('agentPoolMode')]",
          "vmSkuName": "[parameters('agentVmSku')]",
          "labels": "[if(empty(parameters('labels')), json('null'), parameters('labels'))]",
          "taints": "[if(empty(parameters('taints')), json('null'), parameters('taints'))]",
          "agentOptions": "[if(empty(parameters('agentOptions')), json('null'), parameters('agentOptions'))]",
          "attachedNetworkConfiguration": {
            "l2Networks": "[if(empty(parameters('l2Networks')), json('null'), parameters('l2Networks'))]",
            "l3Networks": "[if(empty(parameters('l3Networks')), json('null'), parameters('l3Networks'))]",
            "trunkedNetworks": "[if(empty(parameters('trunkedNetworks')), json('null'), parameters('trunkedNetworks'))]"
          },
          "availabilityZones": "[if(empty(parameters('agentPoolZones')), json('null'), parameters('agentPoolZones'))]",
          "upgradeSettings": {
            "maxSurge": "1"
          }
        },
        "dependsOn": []
      }
    ]
}

阅读文章并保存名为 kubernetes-add-agentpool.json 的模板文件后,继续按下一节所述部署模板。

  1. 创建一个名为 kubernetes-nodepool-parameters.json 的文件,并以 JSON 格式添加所需参数。 可以使用以下示例作为起点。 将值替换成自己的值。
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "kubernetesClusterName":{
        "value": "myNexusK8sCluster"
      },
      "extendedLocation": {
        "value": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/microsoft.extendedlocation/customlocations/<custom-___location-name>"
      }
    }
  }
  1. 部署模板。
    az deployment group create \
      --resource-group myResourceGroup \
      --template-file kubernetes-add-agentpool.json \
      --parameters @kubernetes-nodepool-parameters.json

注释

可以使用初始代理池配置在群集本身的初始创建期间添加多个代理池。 但是,如果要在初始创建之后添加代理池,可以使用上述命令为 Nexus Kubernetes 群集创建其他代理池。

以下输出示例成功创建了代理池。

$ az networkcloud kubernetescluster agentpool list --kubernetes-cluster-name myNexusK8sCluster --resource-group myResourceGroup --output table
This command is experimental and under development. Reference and support levels: https://aka.ms/CLI_refstatus
Count    Location    Mode    Name                          ProvisioningState    ResourceGroup    VmSkuName
-------  ----------  ------  ----------------------------  -------------------  ---------------  -----------
1        eastus      System  myNexusK8sCluster-nodepool-1  Succeeded            myResourceGroup  NC_P10_56_v1
1        eastus      User    myNexusK8sCluster-nodepool-2  Succeeded            myResourceGroup  NC_P10_56_v1

清理资源

不再需要资源组时,可将其删除。 资源组和资源组中的所有资源都会被删除。

使用 az group delete 命令可删除资源组、Kubernetes 群集以及除 Operator Nexus 网络资源外的所有相关资源。

az group delete --name myResourceGroup --yes --no-wait

后续步骤

现在即可直接通过群集连接或通过 Azure Operator Service Manager 来部署 CNF。