Load Balancing
Load balancing is a core part of running scalable, highly available applications in Azure Kubernetes Service (AKS). AKS integrates with Azure’s native load balancing solutions to distribute traffic efficiently to your application pods.
How Load Balancing Works in AKS
When you expose a Kubernetes Service of type LoadBalancer
, AKS automatically provisions an Azure Load Balancer in your cluster’s resource group. This load balancer receives external traffic and forwards it to the appropriate pods running in your cluster.
apiVersion: v1
kind: Service
metadata:
name: my-app
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: my-app
When you create a Service with type: LoadBalancer
, AKS:
- Provisions a public (or internal) Azure Load Balancer.
- Allocates a public IP address (unless you specify an internal load balancer).
- Configures load balancing rules to forward traffic to the backend pods.
The load balancer distributes incoming traffic across all healthy pods matching the selector.
ClusterIP or NodePort
ClusterIP
exposes the service only within the cluster.NodePort
exposes the service on a static port on each node, but does not provision an Azure Load Balancer.