获取运行中Azure Kubernetes集群节点数的KQL查询问题
解决Kusto查询AKS集群节点数返回0的问题
你遇到的问题是因为原查询用的count字段是节点池的目标配置副本数,而非实际运行的节点数,而且没过滤集群和节点池的运行状态。以下是修正后的查询:
Resources | where type == "microsoft.containerservice/managedclusters" | where properties.powerState.code == "Running" // 只保留运行中的集群 | extend nodepools = properties.agentPoolProfiles | mv-expand nodepools | where nodepools.powerState.code == "Running" // 只保留运行中的节点池 | project 集群名称 = name, 节点池名称 = nodepools.name, VM规格 = nodepools.vmSize, 最小节点数 = nodepools.minCount, 最大节点数 = nodepools.maxCount, 集群状态 = properties.powerState.code, 节点池状态 = nodepools.powerState.code, 当前实际节点数 = nodepools.currentCount | sort by 集群名称
关键修正点:
- 新增集群状态过滤:只查询运行中的AKS集群,排除已停止的集群
- 新增节点池状态过滤:只统计运行中的节点池,避免停止的节点池干扰结果
- 用
currentCount替代count:currentCount是节点池当前实际运行的节点数量,count是配置的目标副本数,两者可能因扩容、缩容或节点池启停产生差异
内容的提问来源于stack exchange,提问作者Subhajit Podder
相关产品推荐
相关产品推荐

