How to find the empty aks cluster pools (no pods) using azure rest api?

Diwakar S 40 Reputation points
2023-03-17T07:23:19.3133333+00:00

There is requirement , I need to identify the empty aks cluster pools in the azure subscription. Can we use the agentPoolProfiles for identifying the empty cluster pools or is there any rest api link for finding the empty aks cluster pools?

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,197 questions
No comments
{count} votes

Accepted answer
  1. Andrei Barbu 1,366 Reputation points Microsoft Employee
    2023-03-17T08:04:36.7866667+00:00

    Hello Diwakar S

    Thank you for reaching out.

    When you say "empty", I will assume that you mean node pools that contain nodes without any pods than the ones managed by AKS (for example coredns, konnectivity, kube-proxy and so on).

    In my opinion, there is no way to see that at Azure level because all your nodes will have at least the pods that are created based on the kube-system DaemonSets (like cloud-node-manager, kube-proxy and so on) scheduled on. I don't see how using agentPoolProfiles, Azure REST API or other methods at Azure level would be able to exclude that.

    My suggestion is to use "kubectl" to find out the nodes that are using other pods than the mandatory ones and remove the others.

    For example, the following command will display the namespace, pod name and the name of the node where the pod is scheduled in all namespaces:

    kubectl get pods -o=go-template --template='{{range .items}}{{.metadata.namespace}} {{.metadata.name}} {{.spec.nodeName}}{{"\n"}}{{end}}' -A

    Then you can exclude system pods like azure-ip-masq-agent, cloud-node-manager and so on with the following command in order to find the nodes that you need and remove the others. Please note that you may need to exclude other pods than I added in the command depending on your configuration.

    kubectl get pods -o=go-template --template='{{range .items}}{{.metadata.namespace}} {{.metadata.name}} {{.spec.nodeName}}{{"\n"}}{{end}}' -A | grep -v -e azure-ip-masq-agent -e cloud-node-manager -e coredns -e csi-azure -e konnectivity -e metrics-server -e kube-proxy

    For example on my side, I found that aks-nodepool1-70347334-vmss000001 is hosting application pods and that aks-nodepool1-70347334-vmss000001 is hosting only system pods, so I can remove aks-nodepool1-70347334-vmss000001.

    User's image

    Please note this is just a recommendation and it doesn't mean is the best method or an official one.


    I hope this is helpful. If any clarification needed, let me know and I will do my best to answer.

    Please "Accept as Answer" and Upvote if it helped, so that it can help others in the community looking for help on similar topics.

    Thank you!

0 additional answers

Sort by: Most helpful