<p>I have an AKS-Cluster in Azure. When I scale down the cluster with az aks scale for example I want to control which Node should be removed.</p>

<p>I cannot find a documentation that describes how Azure decides.
Will Azure prefer removing nodes that are already cordoned or drained?</p>

<p>Deleting it from the Azure Portal is not an option, because I want an application to communicate with Azure via CLI or API.</p>

<p>First of all, it's impossible to control which node to remove when you scale down the AKS cluster. Then I will show you how do the nodes change when you scale the AKS cluster.</p>

<p>When you do not use the VMSS as the agent pool, it means the AKS cluster use the individual VMs as the nodes. If you scale up, then it will increase the nodes with the index after the existing nodes. For example, the cluster has one node with the index 0 and then it will use the index 1 if you scale up one node. And if you scale down, it will remove the nodes with the biggest index in the sequence at first.</p>

<p>When you use the VMSS as the agent pool, it will comply with the scale rules of VMSS. And you can see the VMSS scale rules in <a href="https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-faq#if-i-reduce-my-scale-set-capacity-from-20-to-15-which-vms-are-removed" rel="nofollow noreferrer">the changes of VMSS scale up and down</a>.</p>

<p>Also, you can take a look at the Azure CLI command <a href="https://learn.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-scale" rel="nofollow noreferrer"><code>az aks scale</code></a> that scale the AKS cluster and the <a href="https://learn.microsoft.com/en-us/rest/api/aks/agentpools/createorupdate" rel="nofollow noreferrer">REST API</a>.</p>
