简体   繁体   English

通过 Azure 禁用 AKS 节点池的自动缩放 Powershell

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

I have an AKS with 3 Node pools - 2 USER type and 1 SYSTEM type.我有一个带有 3 个节点池的 AKS - 2 个用户类型和 1 个系统类型。 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.我想通过 Azure 运行手册创建自动化,在下班时间将 2 个 USER 类型的节点池缩放为零,然后使用之前的最小和最大计数重新启用对节点池的自动缩放。

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' ^ 为此,我得到一个错误,即 MaxCount 值不能为“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. ^ 对于我没有得到任何错误,但它不会将其缩放为 0,基本上什么都不做。

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这是我使用的 Update-AzAksNodePool 命令的文档: 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.我尝试使用-EnableAutoScaling参数运行它两次,但没有切换它。

I tried running it with -EnableAutoScaling $false , didn't work as well as it doesn't receive value.我尝试使用-EnableAutoScaling $false运行它,但效果不佳,因为它没有收到价值。

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.我发现这样做的唯一方法是通过 Azure CLI - 这在运行手册中不可用,或者通过 Azure 门户 - 无法自动化。

Anyone knows how to turn a Node pool's auto-scaling mode off via Powershell?有人知道如何通过 Powershell 关闭节点池的自动缩放模式吗?

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.使用当前可用的功能,要通过 Powershell 禁用 AKS 节点池的自动缩放,我建议利用代理池 - 创建或更新REST API 和Invoke-RestMethod PowerShell cmdlet,并创建如下所示的 8835877860644 自动化运行手册。

$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"
  }
}
$Body.properties.enableAutoScaling=$false
$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 = @{
    'Content-Type'='application/json'
    '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.另一方面,由于我们具有通过代理池 - 创建或更新REST API 和az aks nodepool update CLI 命令禁用 AKS 节点池自动缩放的功能,因此我们应该也通过直接 Azure PowerShell cmdlet 具有相同的功能。 So, I am reaching out to our internal team to check on this and will keep you updated as I hear more information.因此,我正在与我们的内部团队联系以核实此事,并会在听到更多信息后及时通知您。

UPDATE-1:更新 1: 在此处输入图像描述 在此处输入图像描述 For more information with regards to it, please refer this and this documents.有关它的更多信息,请参阅文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM