KQL query to get the node count of running Aks clusters in azure

Viewed 47

I am new to Kusto. I need an query to get the current node count of all the running Azure kubernetes clusters. I have tried with below but for few clusters it is giving node count 0 where as mode is present on those

Resources
| where type == "microsoft.containerservice/managedclusters"
| extend nodepools = properties.agentPoolProfiles
| mv-expand nodepools
| project name, nodepools.name, nodepools.vmSize, nodepools.minCount, nodepools.maxCount, nodepools.powerState.code,nodeCount = tostring(nodepools['count'])
| sort by name
1 Answers

I tried to get the node count of all the running Azure Kubernetes clusters in azure using the Azure Resource Graph Explorer by using the below query and got the results successfully as shown in the below image:

Resources
 | where type == "microsoft.containerservice/managedclusters"
 | extend properties.agentPoolProfiles
 | project subscriptionId, name, pool = (properties.agentPoolProfiles)
 | mv-expand pool
 | project subscription = subscriptionId, cluster = name, size = pool.vmSize, count = pool.['count']

enter image description here

If any of the Kubernetes service cluster is in stopped state then it's node count will be shown as "0" as shown in the below image:

enter image description here

Related