LoadBalancer Service type¶
The LoadBalancer Service type is a configuration within Kubernetes that exposes services externally using a cloud provider's load balancer^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md]. It is one of the available values for the spec.type field in a Service definition, alongside options like NodePort^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].
Mechanism¶
When a Service is defined as type: LoadBalancer, Kubernetes provisions an external load balancer to distribute traffic across the nodes in the cluster^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].
- Cloud Provider Integration: If the Kubernetes cluster is hosted on a third-party cloud provider (such as Amazon Web Services or Google Cloud Platform), the provider's native load balancer resources are automatically utilized to allocate traffic to the nodes^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].
- Local Environments: In local environments like Docker Desktop, an external IP is typically not provisioned by a cloud provider. Instead, the system often maps the service directly to
localhostfor accessibility^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].
Configuration¶
Defining a LoadBalancer involves setting the Service type to LoadBalancer and configuring port mappings to route external traffic to the target Pods^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].
Key configuration fields include:
spec.selector: Defines which Pods receive the traffic by matching labels^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].spec.ports:port: The port exposed by the Service (Cluster IP).targetPort: The port on the Pod container to which traffic is forwarded^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].nodePort: A specific port on the Node object that maps to thetargetPort^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md].
Related Concepts¶
- Kubernetes Service
- Pod
- [[Labels and Selectors]]
- NodePort
Sources¶
^[400-devops-06-kubernetes-k8s-ithelp-day7-readme.md]