Home > database >  Get Azure Resources in AKS Node Resource Group from Script
Get Azure Resources in AKS Node Resource Group from Script

Time:04-01

When deploying an AKS Cluster you get the AKS Cluster Resource itself and a bunch of separate resources controlled by AKS in a separate resource group. I need to get the name of the VNET AKS is created in to peer it with the network of Application Gateway. All the Azure PowerShell or Azure CLI Commands to get any information about the resources in this Resource Group produce empty results though. I can not even get a List of Resources in this Resource Group.

I tried the following commands

az resource list
Get-AzResource
az network vnet list

But none of them produce any output.

This is also the reason why this tutorial fails at the peering of the virtual networks.

Any idea why this is happening and how to get the name of this VNET?

Update: It took about an hour for this resource group to be available via script although i could see it in the portal right after the deployment. Is there any trick to get access to these resources right after the deployment so i can automate subsequent steps building on the availability of those resources?

CodePudding user response:

nodeResourceGroup=$(az aks show -g AKS_RG -n AKS_NAME -o tsv --query nodeResourceGroup)
az network vnet list -g $nodeResourceGroup -o tsv --query "[0].name"

You can also create the VNET and Subnet by yourself upfront and then place the AKS in this networks.

This is in my view the better solution instead of letting Azure manage all this resources and as benefit you are more flexible with peering etc.

I would also re-commend to use an IaC tool like Terraform or Bicep for this.

  • Related