Hi MOUTAMA Marina,
Welcome to Microsoft Q&A and thank you for posting your query here!
I hope the answer provided by "Michele" is helpful to you and i would like to add few more learn documents links and information for your reference, i hope these will help full to you.
So, the answer is Yes for your question i.e. " Is it expected behavior that the NAT Gateway takes precedence over the Load Balancer outbound IPs? "
When you attach a NAT Gateway (managed or user-assigned) to a subnet used by AKS, it takes priority over all other outbound methods, including the Load Balancer’s outbound rules or public IP configurations.
Refer: https://learn.microsoft.com/en-us/azure/load-balancer/load-balancer-outbound-connections
That means once a NAT Gateway is associated with the subnet, all new outbound connections from your cluster will use the NAT Gateway’s IP(s). Existing connections using the Load Balancer IP continue until they close, but as soon as they do, all new traffic flows will originate from the NAT Gateway
Refer: https://learn.microsoft.com/en-us/azure/nat-gateway/faq.
Below is the response for your 2nd query i.e. "If both are present, which outbound IP(s) will be used by the cluster for egress traffic? "
The Load Balancer will continue to handle existing connections until they close, but all new connections will use the public IP addresses associated with the NAT Gateway. This is a deliberate design by Azure. The NAT Gateway is a more scalable and resilient solution for outbound connectivity and is designed to take over when it's present.
Refer: https://docs.azure.cn/en-us/nat-gateway/nat-overview
below is the recommended solution for this:
The recommended solution is to use the NAT Gateway as your primary method for egress traffic. NAT Gateway is designed to solve the problem of Source Network Address Translation (SNAT) port exhaustion, a common issue with Load Balancers, especially for clusters with a large number of pods making many outbound connections. NAT Gateway provides a large pool of SNAT ports (up to 64,512 per public IP address) and automatically scales to meet your demand without the need for manual configuration.
To configure your AKS cluster for this setup, you should:
Detach the Load Balancer: Modify your AKS cluster to use outboundType of managedNATGateway or userAssignedNATGateway. This will explicitly configure the cluster to rely on the NAT Gateway for all egress traffic.
Verify Egress IP: Once configured, you can verify that the cluster is using the NAT Gateway's public IP address for egress traffic.
Inbound Traffic: A Load Balancer can still be used for inbound traffic to your cluster. When you set the outboundType to NAT Gateway, AKS will still create a Load Balancer for inbound purposes if you create a Kubernetes service of type LoadBalancer
Refer: https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype
if you found the above response is helpful to you, please do not forget to "Accept the answer" and “Upvote it" this can be beneficial to other community members.
Thank you again for your time. I’m happy to continue supporting you—your experience and insights can also benefit others in the community.
Thanks,
Harish.