在 Azure Kubernetes 服务 (AKS) 群集中缩放节点数Scale the node count in an Azure Kubernetes Service (AKS) cluster

如果资源需要更改应用程序,可以手动缩放 AKS 群集以运行不同数量的节点。If the resource needs of your applications change, you can manually scale an AKS cluster to run a different number of nodes. 节点数减少时,节点会被仔细封锁和排除,尽量避免对正在运行的应用程序造成中断。When you scale down, nodes are carefully cordoned and drained to minimize disruption to running applications. 纵向扩展时,AKS 会一直等待,直到节点被 Kubernetes 群集标记为 Ready,然后才在这些节点上计划 Pod。When you scale up, AKS waits until nodes are marked Ready by the Kubernetes cluster before pods are scheduled on them.

缩放群集节点Scale the cluster nodes

首先,使用 az aks show 命令获取节点池的名称**。First, get the name of your node pool using the az aks show command. 以下示例获取 myResourceGroup 资源组中名为 myAKSCluster 的群集的节点池名称****:The following example gets the node pool name for the cluster named myAKSCluster in the myResourceGroup resource group:

az aks show --resource-group myResourceGroup --name myAKSCluster --query agentPoolProfiles

以下示例输出表明名称为 nodepool1****:The following example output shows that the name is nodepool1:

[
  {
    "count": 1,
    "maxPods": 110,
    "name": "nodepool1",
    "osDiskSizeGb": 30,
    "osType": "Linux",
    "storageProfile": "ManagedDisks",
    "vmSize": "Standard_DS2_v2"
  }
]

使用 az aks scale 命令缩放群集节点。Use the az aks scale command to scale the cluster nodes. 以下示例将名为 myAKSCluster 的群集缩放为单个节点。The following example scales a cluster named myAKSCluster to a single node. 提供前一个命令中你自己的 --nodepool-name,如 nodepool1:Provide your own --nodepool-name from the previous command, such as nodepool1:

az aks scale --resource-group myResourceGroup --name myAKSCluster --node-count 1 --nodepool-name <your node pool name>

以下示例输出显示群集已成功缩放为一个节点,如 agentPoolProfiles 部分中所示**:The following example output shows the cluster has successfully scaled to one node, as shown in the agentPoolProfiles section:

{
  "aadProfile": null,
  "addonProfiles": null,
  "agentPoolProfiles": [
    {
      "count": 1,
      "maxPods": 110,
      "name": "nodepool1",
      "osDiskSizeGb": 30,
      "osType": "Linux",
      "storageProfile": "ManagedDisks",
      "vmSize": "Standard_DS2_v2",
      "vnetSubnetId": null
    }
  ],
  [...]
}

User 节点池缩放为 0Scale User node pools to 0

与始终需要运行节点的 System 节点池不同,User 节点池允许缩放为 0。Unlike System node pools that always require running nodes, User node pools allow you to scale to 0. 若要详细了解系统节点池和用户节点池之间的差异,请参阅系统节点池和用户节点池To learn more on the differences between system and user node pools, see System and user node pools.

若要将用户池缩放为 0,可以使用 az aks nodepool scale 来替代上面的 az aks scale 命令,并将 0 设置为节点计数。To scale a user pool to 0, you can use the az aks nodepool scale in alternative to the above az aks scale command, and set 0 as your node count.

az aks nodepool scale --name <your node pool name> --cluster-name myAKSCluster --resource-group myResourceGroup  --node-count 0 

还可以通过将群集自动缩放程序--min-count 参数设置为 0,将 User 节点池自动缩放为 0 个节点。You can also autoscale User node pools to 0 nodes, by setting the --min-count parameter of the Cluster Autoscaler to 0.

后续步骤Next steps

在本文中,你手动缩放了 AKS 群集以增加或减少节点数量。In this article, you manually scaled an AKS cluster to increase or decrease the number of nodes. 还可以使用群集自动缩放程序自动缩放群集。You can also use the cluster autoscaler to automatically scale your cluster.