Author : MD TAREQ HASSAN | Updated : 2021/05/05
Load Balancer Type Service
- Load Balancer type service exposes appllications (pods) running inside cluster to external clients
- Load Balancer Type Service is implemented using cloud providers Load Balancer i.e. Azure Load Balancer
- In case of Load Balancer Type K8s Service:
- There is always a ClusterIP service in-front of Pods
- There is NodePort service between ClusterIP and Load Balancer
- Load Balancer communicates to ClusterIP via NodePort service
- Pods <-> CLusterIP <-> NodePort <-> LoadBalancer
Points To Be Noted
- In Azure, when AKS is provisioned (in Azure portal) with availability zones:
- VM ScaleSet will be provisioned automatically
- A load balancer will be provisioned automatically and put in-front of AKS cluster of worker nodes
- The AKS standard load balancer is to support availability zones and auto-scaling for AKS cluster of worker nodes
- This standard load balancer has nothing to do with K8s “Load Balancer” type service
- The control plane is managed by Microsoft, so this standard load balancer has nothing to do with control plane either
Creating Load Balancer Service
- On cloud providers which support external load balancers, setting the type field to LoadBalancer provisions a load balancer for your Service
- The actual creation of the load balancer happens asynchronously, and information about the provisioned balancer is published in the Service’s
.status.loadBalancer
field - A range of node ports (range of ports from node VM/PC) are allocated by default when a service of type LoadBalancer is created
- By default a LoadBalancer type of Service uses the cloud provider’s default load balancer implementation
- The cloud provider decides how it is load balanced
- The set of protocols that can be used for LoadBalancer type of Services is still defined by the cloud provider
- See:
Example
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
clusterIP: 10.0.171.239
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 192.0.2.127
Internal Load Balancer
In a mixed environment it is sometimes necessary to route traffic from Services inside the same (virtual) network address block.
To set an internal load balancer, add one of the following annotations (varies depending on the cloud Service provider)
[...]
metadata:
name: my-service
annotations:
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
[...]