停止 AKS(Azure 托管 Kubernetes)中的所有计算

Stop all compute in AKS (Azure Managed Kubernetes)

我在 Azure 中创建了一个托管 Kubernetes 集群,但它仅用于学习目的,因此我只想在实际使用时支付计算费用。

是否有一种简单的方法可以正常关闭和启动 VM、可用性集和负载平衡器?

在所有 AKS 资源中,只有 VM 会花钱(当然,VHD 也是如此,但您无法真正阻止它们)。所以你只需要照顾那些。编辑:Public Ips 也要花钱,但你也不能阻止它们。

对于我的 AKS 集群,我只使用门户并发出 stop\deallocate 命令。并在我需要它们时重新启动它们(一切似乎都运行良好)。

您可以使用 REST API\powershell\cli\various SKD 以自动化方式实现相同的结果。

您可以使用 Azure CLI to stop the the entire cluster:

az aks stop --name myAksCluster --resource-group myResourceGroup

然后用

重新开始
az aks start --name myAksCluster --resource-group myResourceGroup

在此功能之前,可以通过 Powershell 停止虚拟机:

az vm deallocate --ids $(az vm list -g MC_my_resourcegroup_westeurope --query "[].id" -o tsv)

MC_my_resourcegroup_westeurope 替换为包含 VM 的资源组的名称。

当您想再次启动 VM 时,运行:

az vm start --ids $(az vm list -g MC_my_resourcegroup_westeurope --query "[].id" -o tsv)

在您的 AKS 群集中,转到属性并找到您的资源组名称。搜索资源组,当您 select 它时,它会列出您的虚拟机。对于每个虚拟机,select Operations > Auto-Shutdown 选项并将其打开。这将在您不进行开发时关闭 VM 以节省您的钱!要再次打开它们,您将需要按照之前答案或答案 here

中的建议进行操作

上述方法 (az vm <deallocate|start> --ids $(...)) 似乎不再有效。

通过首先列出 VM 规模集并将其用于 deallocate/start:

来解决
$ResourceGroup = "MyResourceGroup"
$ClusterName = "MyAKSCluster"
$Location = "westeurope"

$vmssResourceGroup="MC_${ResourceGroup}_${ClusterName}_${Location}"

# List all VM scale sets
$vmssNames=(az vmss list --resource-group $vmssResourceGroup --query "[].id" -o tsv | Split-Path -Leaf)

# Deallocate first instance for each VM scale set
$vmssNames | ForEach-Object { az vmss deallocate --resource-group $vmssResourceGroup --name $_  --instance-ids 0}

# Start first instance for each VM scale set
$vmssNames | ForEach-Object { az vmss start --resource-group $vmssResourceGroup --name $_  --instance-ids 0}

AKS 刚刚添加了一项新功能:

The AKS Stop/Start cluster feature now in public preview allows AKS customers to completely pause an AKS cluster and pick up where they left off later with a switch of a button, saving time and cost. Previously, a customer had to take multiple steps to stop or start a cluster, adding to operations time and wasting compute resources. The stop/start feature keeps cluster configurations in place and customers can pick up where they left off without reconfiguring the clusters.

https://docs.microsoft.com/en-gb/azure/aks/start-stop-cluster