Disable Auto-Scaling of an AKS Node pool via Azure Powershell

teamdever 21 Reputation points

I have an AKS with 3 Node pools - 2 USER type and 1 SYSTEM type. I want to create an automation via Azure runbooks that will scale the 2 USER type Node pools to zero during off-hours and then re-enable auto-scaling to the Node pools with their previous Min and Max count.

As for re-enabling the auto-scaling I found the command for that:

Update-AzAksNodePool -ResourceGroupName $ResourceGroupName -ClusterName $AKSCluster -Name $NodePool -MinCount <Min number> -MaxCount <Max number> -EnableAutoScaling  

But as for scaling them to zero, the following commands didn't work:

Update-AzAksNodePool -ResourceGroupName $ResourceGroupName -ClusterName $AKSCluster -Name $NodePool -MinCount 0 -MaxCount 0   

^ For this I get an error that MaxCount value can't be '0'

Update-AzAksNodePool -ResourceGroupName $ResourceGroupName -ClusterName $AKSCluster -Name $NodePool -NodeCount 0  

^ For the I don't get any error but it doesn't scale it to 0, basically does nothing.

So after this I realized that the Node pool must be in Manual scaling mode and not Autoscale for the former command to work, which means my script needs to disable the Node pool's auto-scaling or switch it to Manual scaling mode.

This is the documentation I used of the Update-AzAksNodePool command: https://learn.microsoft.com/en-us/powershell/module/az.aks/update-azaksnodepool?view=azps-7.3.2

The documentation does not mention any parameter to disable auto-scaling, only to enable it. I tried running it twice with the -EnableAutoScaling parameter, didn't switch it.

I tried running it with -EnableAutoScaling $false, didn't work as well as it doesn't receive value.

There was nothing in the documentation that mentioned disabling the auto-scaling. The only way I found doing it was via Azure CLI - which isn't available in a runbook, or via the Azure Portal - which can't be automated.

Anyone knows how to turn a Node pool's auto-scaling mode off via Powershell?

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,931 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,159 questions
0 comments No comments
{count} votes

Accepted answer
  1. tbgangav-MSFT 10,406 Reputation points

    Hi @teamdever ,

    With the features that are currently available, to disable an AKS node pool's auto-scaling via Powershell, I would recommend to leverage Agent Pools - Create Or Update REST API and Invoke-RestMethod PowerShell cmdlets and create an Azure Automation runbook something as shown below.

    $SubscriptionID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"  
    $ResourceGroupName = "xxxxxxxxxxxxxxxxxxxxxx"  
    $AKSClusterName = "xxxxxxxxxxxxxxxxxxx"  
    $AgentPoolName = "xxxxxxxxxxxxxxxxxxx"  
    $URI = "https://management.azure.com/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroupName/providers/Microsoft.ContainerService/managedClusters/$AKSClusterName/agentPools/$AgentPoolName"+"?api-version=2022-01-01"  
    $Body = @{  
      properties = @{  
        enableAutoScaling = "false";  
        mode = "System"  
    $JSONBody = $Body | ConvertTo-Json  
    $azContext = (Connect-AzAccount -Identity).context  
    $azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile  
    $profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)  
    $token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)  
    $authHeader = @{  
        'Authorization'='Bearer ' + $token.AccessToken  
    $response = Invoke-RestMethod -Uri $URI -Method PUT -Headers $authHeader -Body $JSONBody  
    $response | fl *  



    On the other hand, as we have feature to disable AKS node pool's auto-scaling via Agent Pools - Create Or Update REST API and az aks nodepool update CLI commands so we are supposed to have the same feature via direct Azure PowerShell cmdlet as well. So, I am reaching out to our internal team to check on this and will keep you updated as I hear more information.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful