跳转到内容

扩缩节点池

  • 功能名称: 扩缩标准节点池
  • API 版本: 2018-05-25
  • API 名称: ModifyClusterNodePool
  • 文档更新时间: 2026-06-17
  • Agent 友好度: ⭐⭐⭐⭐⭐

通过 ModifyClusterNodePool 可以调整节点池的伸缩开关、最小节点数、最大节点数、标签、污点、资源标签和删除保护等配置。节点池扩缩容适用于业务高峰扩容、低峰缩容、压测临时扩容和成本优化。

!!! warning “自动伸缩与手动期望数” 标准节点池由弹性伸缩能力管理节点数量。开启自动伸缩时,应主要调整 MinNodesNumMaxNodesNum 和伸缩策略;如果需要固定节点数量,先确认当前节点池是否允许手动调整期望容量,避免与自动伸缩控制器互相覆盖。


  • 已创建节点池,并记录 NodePoolId
  • 集群和节点池状态正常
  • 扩容前确认 CVM、CBS、ENI、子网 IP 和账户余额充足
  • 缩容前确认业务 Pod 可迁移,关键工作负载已配置 PDB

参数名必填类型说明示例值
ClusterIdString集群 IDcls-xxxxxxxx
NodePoolIdString节点池 IDnp-xxxxxxxx
NameString节点池名称production-pool
MinNodesNumInteger最小节点数3
MaxNodesNumInteger最大节点数20
EnableAutoscaleBoolean是否开启自动伸缩true
LabelsArray节点标签env=production
TaintsArray节点污点dedicated=backend:NoSchedule
TagsArray腾讯云资源标签cost-center=cc-1001
DeletionProtectionBoolean删除保护开关true

Terminal window
tccli tke DescribeClusterNodePoolDetail \
--Region ap-guangzhou \
--ClusterId cls-xxxxxxxx \
--NodePoolId np-xxxxxxxx

关注以下字段:

  • NodeCountSummary: 当前节点数量
  • AutoscalingGroupStatus: 伸缩组状态
  • MaxNodesNum / MinNodesNum: 伸缩范围
  • Labels / Taints: 调度相关配置
Terminal window
tccli tke ModifyClusterNodePool \
--Region ap-guangzhou \
--ClusterId cls-xxxxxxxx \
--NodePoolId np-xxxxxxxx \
--EnableAutoscale true \
--MinNodesNum 3 \
--MaxNodesNum 20
Terminal window
tccli tke ModifyClusterNodePool \
--Region ap-guangzhou \
--ClusterId cls-xxxxxxxx \
--NodePoolId np-xxxxxxxx \
--Labels '[
{"Name": "env", "Value": "production"},
{"Name": "workload-type", "Value": "backend"}
]' \
--Taints '[
{"Key": "dedicated", "Value": "backend", "Effect": "NoSchedule"}
]'

Step 4: 使用 Python SDK 修改伸缩范围

Section titled “Step 4: 使用 Python SDK 修改伸缩范围”
from tencentcloud.common import credential
from tencentcloud.tke.v20180525 import models, tke_client
cred = credential.Credential("SecretId", "SecretKey")
client = tke_client.TkeClient(cred, "ap-guangzhou")
req = models.ModifyClusterNodePoolRequest()
req.ClusterId = "cls-xxxxxxxx"
req.NodePoolId = "np-xxxxxxxx"
req.EnableAutoscale = True
req.MinNodesNum = 3
req.MaxNodesNum = 20
resp = client.ModifyClusterNodePool(req)
print(f"RequestId: {resp.RequestId}")

Terminal window
tccli tke DescribeClusterNodePoolDetail \
--Region ap-guangzhou \
--ClusterId cls-xxxxxxxx \
--NodePoolId np-xxxxxxxx
Terminal window
kubectl get nodes -l node-pool=production-pool -o wide
kubectl describe node <node-name>
Terminal window
kubectl get pods -A -o wide
kubectl describe pod <pod-name> -n <namespace>

  1. 缩容前先确认节点上的 Pod 可以被驱逐。
  2. 对关键服务配置 PodDisruptionBudget,避免一次性驱逐过多副本。
  3. 使用污点、亲和性或节点标签控制业务迁移范围。
  4. 如果节点池开启自动伸缩,不要长期手动修改节点数量。
  5. 缩容后检查 PVC、DaemonSet、日志采集和监控组件状态。

问题可能原因处理方式
扩容后节点未创建配额不足、库存不足、子网 IP 不足检查 CVM 库存、AS 活动记录和子网 IP
缩容卡住Pod 无法驱逐或 PDB 限制检查 kubectl drain 输出和 PDB
新标签未生效存量节点未同步或被忽略检查节点池修改参数和节点实际标签
Pod 不调度到新节点污点未容忍或选择器不匹配检查 tolerations、nodeSelector、affinity