how to get hold of the azure kubernetes cluster outbound ip address

10/6/2021

we have a basic AKS cluster setup and we need to whitelist this AKS outbound ipadress in one of our services, i scanned the AKS cluster setting in Azure portal, i was not able to find any outbound IpAddress.

how do we get the outboud IP ?

Thanks -Nen

-- nen
azure
azure-aks
kubernetes

2 Answers

10/6/2021

You can define AKS to route egress traffic via a Load-Balancer (this is also the default behavior). This also helps you to "use" the same outgoing IP with multiple nodes.

More details are available here.

-- Nico Meisenzahl
Source: StackOverflow

10/6/2021

If you are using an AKS cluster with a Standard SKU Load Balancer i.e.

$ az aks show -g $RG -n akstest --query networkProfile.loadBalancerSku -o tsv
Standard

and the outboundType is set to loadBalancer i.e.

$ az aks show -g $RG -n akstest --query networkProfile.outboundType -o tsv
loadBalancer

then you should be able to fetch the outbound IP addresses for the AKS cluster like:

$ az aks show -g $RG -n akstest --query networkProfile.loadBalancerProfile.effectiveOutboundIps[].id
[
    "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/MC_xxxxxx_xxxxxx_xxxxx/providers/Microsoft.Network/publicIPAddresses/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
]
# Using $PUBLIC_IP_RESOURCE_ID obtained from the last step
$  az network public-ip show --ids $PUBLIC_IP_RESOURCE_ID --query ipAddress -o tsv
xxx.xxx.xxx.xxx

For more information please check Use a public Standard Load Balancer in Azure Kubernetes Service (AKS)


If you are using an AKS cluster with a Basic SKU Load Balancer i.e.

$ az aks show -g $RG -n akstest --query networkProfile.loadBalancerSku -o tsv
Basic

and the outboundType is set to loadBalancer i.e.

$ az aks show -g $RG -n akstest --query networkProfile.outboundType -o tsv
loadBalancer

Load Balancer Basic chooses a single frontend to be used for outbound flows when multiple (public) IP frontends are candidates for outbound flows. This selection is not configurable, and you should consider the selection algorithm to be random. This public IP address is only valid for the lifespan of that resource. If you delete the Kubernetes LoadBalancer service, the associated load balancer and IP address are also deleted. If you want to assign a specific IP address or retain an IP address for redeployed Kubernetes services, you can create and use a static public IP address, as @nico-meisenzahl mentioned.

The static IP address works only as long as you have one Service on the AKS cluster (with a Basic Load Balancer). When multiple addresses are configured on the Azure Load Balancer, any of these public IP addresses are a candidate for outbound flows, and one is selected at random. Thus every time a Service gets added, you will have to add that corresponding IP address to the whitelist which isn't very scalable. [Reference]


In the latter case, we would recommend setting outBoundType to userDefinedRouting at the time of AKS cluster creation. If userDefinedRouting is set, AKS won't automatically configure egress paths. The egress setup must be done by you.

The AKS cluster must be deployed into an existing virtual network with a subnet that has been previously configured because when not using standard load balancer (SLB) architecture, you must establish explicit egress. As such, this architecture requires explicitly sending egress traffic to an appliance like a firewall, gateway, proxy or to allow the Network Address Translation (NAT) to be done by a public IP assigned to the standard load balancer or appliance.

Load balancer creation with userDefinedRouting

AKS clusters with an outbound type of UDR receive a standard load balancer (SLB) only when the first Kubernetes service of type 'loadBalancer' is deployed. The load balancer is configured with a public IP address for inbound requests and a backend pool for inbound requests. Inbound rules are configured by the Azure cloud provider, but no outbound public IP address or outbound rules are configured as a result of having an outbound type of UDR. Your UDR will still be the only source for egress traffic.

Azure load balancers don't incur a charge until a rule is placed.

!! Important: Using outbound type is an advanced networking scenario and requires proper network configuration.

Here's instructions to Deploy a cluster with outbound type of UDR and Azure Firewall

-- Srijit_Bose-MSFT
Source: StackOverflow