<p>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.</p>
<p>I can obtain the load balancer resource using...</p>
<pre><code>az resource list --resource-group $k8sResourceGroup --query &quot;[?type=='Microsoft.Network/loadBalancers']&quot;
</code></pre>
<p>I obtain the <code>id</code> from that response and pass it to...</p>
<pre><code>az network lb show --id $loadBalancer.id --output json | convertfrom-json).frontendIpConfigurations
</code></pre>
<p>The <code>frontendIpConfigurations</code> 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...</p>
<pre><code>az network lb show --id $loadBalancer.id --output json | convertfrom-json).frontendIpConfigurations | where-object { $null -ne $_.loadBalancingRules }).loadBalancingRules[0].id
</code></pre>
<p>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...</p>
<pre><code>az network public-ip show --ids $loadBalancingRuleId --query &quot;{fqdn: dnsSettings.fqdn, address: ipAddress}&quot;
</code></pre>
<p>...I get...</p>
<blockquote>
<p>ResourceNotFoundError: The Resource 'Microsoft.Network/publicIPAddresses/kubernetes' under resource group '[my resource group name]' was not found. For more details please go to <a href="https://aka.ms/ARMResourceNotFoundFix" rel="nofollow noreferrer">https://aka.ms/ARMResourceNotFoundFix</a></p>
</blockquote>
<p>Is there a straightforward method of obtaining an AKS load balancer's public inbound IP address?</p>

<p>Try this (assuming, your LB only has one inbound IP address. Otherwise $pipId is an array)</p>
<pre><code>$pipId = $(az network lb show --id $loadBalancer.id --query &quot;frontendIpConfigurations | [?loadBalancingRules != null].publicIpAddress.id&quot; -o tsv)

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

</code></pre>
