1
votes

I have Kubernetes running on Azure, and it uses a load balancer. Azure has assigned a public IP address to this load balancer, and for the purposes of setting up an Application Gateway via the Azure CLI I wish to obtain the IP address of the k8s load balancer using the Azure CLI.

I can obtain the load balancer resource using...

az resource list --resource-group $k8sResourceGroup --query "[?type=='Microsoft.Network/loadBalancers']"

I obtain the id from that response and pass it to...

az network lb show --id $loadBalancer.id --output json | convertfrom-json).frontendIpConfigurations

The frontendIpConfigurations array contains two objects: an inbound IP address (resource) and an outbound IP address (resource). I filter down to the inbound IP resource like this...

az network lb show --id $loadBalancer.id --output json | convertfrom-json).frontendIpConfigurations | where-object { $null -ne $_.loadBalancingRules }).loadBalancingRules[0].id

I then have something which looks a lot like the IP address resource's ID - it matches that which I see in the Azure portal. But if I then request the resource itself, using...

az network public-ip show --ids $loadBalancingRuleId --query "{fqdn: dnsSettings.fqdn, address: ipAddress}"

...I get...

ResourceNotFoundError: The Resource 'Microsoft.Network/publicIPAddresses/kubernetes' under resource group '[my resource group name]' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix

Is there a straightforward method of obtaining an AKS load balancer's public inbound IP address?

2

2 Answers

1
votes

Try this (assuming, your LB only has one inbound IP address. Otherwise $pipId is an array)

$pipId = $(az network lb show --id $loadBalancer.id --query "frontendIpConfigurations | [?loadBalancingRules != null].publicIpAddress.id" -o tsv)

$ip = (az network public-ip show --ids $pipId --query "ipAddress" -o tsv)

0
votes

Is there a straightforward method of obtaining an AKS load balancer's public inbound IP address?

All the public IPs associated with the Load Balancer of the AKS are the inbound IPs, except the outbound IP. And all the inbound IPs are the public IPs of the services in the AKS. It means if you know how many services with the load balancer type, then you will know how many public inbound IPs associated with the load balancer of the AKS.

According to this cognition, you just need to get the public IP address of the service, then you can get the resource ID of this public IP through Azure CLI:

az network public-ip list --query "[?ipAddress=='publicIPAddress'].id" -o tsv