I have created a managed Kubernetes cluster in Azure, but it's only for learning purposes and so I only want to pay for the compute whilst I'm actually using it.
Is there a easy way to gracefully shut down and start up the VMs, availablity sets and load balancers?
You could use the Azure CLI to stop the the entire cluster:
az aks stop --name myAksCluster --resource-group myResourceGroup
And start it again with
az aks start --name myAksCluster --resource-group myResourceGroup
Before this feature, it was possible to stop the virtual machines via Powershell:
az vm deallocate --ids $(az vm list -g MC_my_resourcegroup_westeurope --query "[].id" -o tsv)
Replace MC_my_resourcegroup_westeurope with the name of your resource group that contains the VM(s).
When you want to start the VM(s) again, run:
az vm start --ids $(az vm list -g MC_my_resourcegroup_westeurope --query "[].id" -o tsv)
Only VMs cost money out of all AKS resources (well, VHDs as well, but you cannot really stop those). So you only need to take care of those. Edit: Public Ips also cost money, but you cannot stop those either.
For my AKS cluster I just use portal and issue stop\deallocate command. And start those back when I need them (everything seems to be working fine).
You can use REST API\powershell\cli\various SKDs to achieve the same result in an automated fashion.
Above method (az vm <deallocate|start> --ids $(...)) no longer seems to work.
Solved by first listing the VM scale sets and use these to 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}
There is a new feature just added to 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://learn.microsoft.com/en-gb/azure/aks/start-stop-cluster
In your AKS cluster, goto properties and find your Resource group name. search for the Resource group and when you select it, it will list your virtual machines. For each Virtual Machine, select the Operations > Auto-Shutdown option and turn it on. This will turn the VM off saving you money when you aren't developing! To turn them back on again, you will need to follow the advice on previous answers or the answer here
Related
I have two resource groups in Azure, each contains one VMSS (Virtual Machine Scale Sets) and the resources are visible in Azure Portal. The problem is, the following commands return empty output:
az resource list --subscription MySubscription -g vmss-rg
az vmss list --subscription MySubscription -g vmss-rg
az vmss list
However, running az resource list with different resource groups which doesn't have VMSS works fine. I also tested it with different Azure account and subscription, it also worked.
We have tested the same command in our local as suggested by #VenkateshDodda-MT and it works fine. Posting it as an answer to help other community members for the similar issue so that they can find and fix their problem.
To achieve the above requirement we need to install the az powershell module in our local .
Post that run the command in powershell to get the vmss list under our subscription or resource groups:-
az resource list --resource-type "Microsoft.Compute/virtualMachineScaleSets"
OUTPUT:-
To get the VMSS list under particular resource group run the below cmd:
az resource list --resource-type "Microsoft.Compute/virtualMachineScaleSets" -g '<rgName>'
OUTPUT:-
For more information please refer this SO THREAD:Azure PS command returns empty list as suggested by #Olga Osinskaya - MSFT
I created an aks using az cli with minimal parameters and specified a node-count and auto scaling. This created a nodepool and VMSS etc. and an accompanying vnet and subnet automatically.
How do I find out the created vnet and subnet using az cli?
az aks nodepool list --cluster-name aks -g rg-aks
report vnetSubnetId and podSubnetId as null.
Using
az vmss list
does show the subnet but I haven't found any properties of the vmss linking it to the nodepool or aks cluster to enable finding it.
The autogenerated name is something like:
aks-nodepool1-15343534-vmss
Which I guess I could filter for along the lines of aks-nodepool1-*-vmss but that seems dodgy and flaky.
I have tested in my environment
The VNET is created along with the VMSS in a different resource group which starts with MC_
To get the subnet ID, you can use the below script:
$CLUSTER_RESOURCE_GROUP = az aks show --resource-group RGName --name AKSClusterName --query nodeResourceGroup -o tsv
$VMSS_NAME = az vmss list -g $CLUSTER_RESOURCE_GROUP --query "[0].name"
az vmss show -g $CLUSTER_RESOURCE_GROUP -n $VMSS_NAME --query virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].subnet.id
I have spot instance nodes in Azure Kubernetes Cluster. I want to simulate the eviction of a node so as to debug my code but not able to. All I could find in azure docs is we can simulate eviction for a single spot instance, using the following:
az vm simulate-eviction --resource-group test-eastus --name test-vm-26
However, I need to simulate the eviction of a spot node pool or a spot node in an AKS cluster.
For simulating evictions, there is no AKS REST API or Azure CLI command because evictions of the underlying infrastructure is not handled by AKS RP.
Only during creation of the AKS cluster the AKS RP can set eviction Policy on the underlying infrastructure by instructing the Azure Compute RP to do so.
Instead to simulate the eviction of node infrastructure, the customer can use az vmsss simulate-eviction command or the corresponding REST API.
az vmss simulate-eviction
az vmss simulate-eviction --instance-id
--name
--resource-group
[--subscription]
Reference Documents:
https://learn.microsoft.com/en-us/cli/azure/vmss?view=azure-cli-latest#az_vmss_simulate_eviction
https://learn.microsoft.com/en-us/rest/api/compute/virtual-machine-scale-set-vms/simulate-eviction
Use the following commands to get the name of the vmss with nodepool:
1.
az aks nodepool list -g $ClusterRG --cluster-name $ClusterName -o
table
Get the desired node pool name from the output
2.
CLUSTER_RESOURCE_GROUP=$(az aks show –resource-group YOUR_Resource_Group --name YOUR_AKS_Cluster --query
nodeResourceGroup -o tsv)
az vmss list -g $CLUSTER_RESOURCE_GROUP --query "[?tags.poolName == '<NODE_POOL_NAME>'].{VMSS_Name:name}" -o tsv
References:
https://louisshih.gitbooks.io/kubernetes/content/chapter1.html
https://ystatit.medium.com/azure-ssh-into-aks-nodes-471c07ad91ef
https://learn.microsoft.com/en-us/cli/azure/vmss?view=azure-cli-latest#az_vmss_list_instances
(you may create vmss if you dont have it configured. Refer :create a VMSS)
I need to deploy Azure container instance in differents Resource Groups.
In one Resource Group I allocate only the ACI and on another Resource Group I allocate the Vnet
Is this possible? I think that is not possible by design
It's possible.
You can create an azure container instance in a virtual network that is in a different resource group from the container instance resource group.
Suppose you have created a vNet myvnet and subnet aci-subnet in the RG myvnetRG for your ACI. Then you could use the following deployment examples.
VnetId=$(az network Vnet show -g myvnetRG -n myvnet --query 'id' -o tsv)
az container create -n appcontainer -g containerRG --image mcr.microsoft.com/azuredocs/aci-helloworld --vnet $VnetId --subnet aci-subnet
You can also deploy a container group to an existing virtual network by using a YAML file, then specify several additional properties like network profile and ID in the YAML.
It is possible by design, but why would you want to do that? It is not a recommended design thought.
If your resource groups in the different regions, you could configure a Vnet-to-Vnet connection. For your reference:
https://learn.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-howto-vnet-vnet-resource-manager-portal
I have created a function app against a new consumption plan with the following command:
az functionapp create
--resource-group myresourcegroup
--storage-account mystorageaccount
--name myfunctionapp
--runtime node
--consumption-plan-location northeurope
This creates the function app correctly, but the app service plan is called NorthEuropePlan, which does not meet the naming guidelines I am following. I cannot see anything in the docs that will allow me to change this name.
Therefore, I would like to create the app service plan before, as a consumption plan (tier Y1 Dynamic), and then create a function app against this plan.
az resource create
--resource-group myresourcegroup
--name myconsumptionplan
--resource-type Microsoft.web/serverfarms
--is-full-object
--properties "{\"location\":\"northeurope\",\"sku\":{\"name\":\"Y1\",\"tier\":\"Dynamic\"}}"
That command works correctly, and creates me an app service plan. However, when I try to use that plan (substituting --consumption-plan-location northeurope for --plan myconsumptionplan), I get this error:
There was a conflict. AlwaysOn cannot be set for this site as the plan does not allow it.
Do I need to specify some more configuration when I make the app service plan?
When I run az appservice plan show against NorthEuropePlan and myconsumptionplan, the only difference in the object that comes back is the name.
When you are using --plan I believe the run time will think it is an App Service Plan and will configure Always ON which is not allowed in consumption plan so I guess you cannot do it like the way you are doing.
You can achieve it with ARM template though. Below is the example command:
az group create
--name ExampleGroup
--location "North Europe"
az group deployment create
--name ExampleDeployment
--resource-group ExampleGroup
--template-uri "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-function-app-create-dynamic/azuredeploy.json"
The URL mentioned in the template-uri is sample template which will create consumption-pan, storage and functionapp.
Deployment will ask the name of parameters (appName) at runtime.