LoadBalancer β Cloud Provider Integration
A LoadBalancer Service provisions an external load balancer from your cloud provider (AWS ELB, GCP Load Balancer, Azure Load Balancer). It exposes your Service to the internet.
This is the standard way to expose HTTP services in production on managed Kubernetes clusters.
How LoadBalancer Works
Internet
β
βΌ
ββββββββββββββββββββββββββββββββ
β Cloud Load Balancer (ELB) β
β External IP: 52.10.1.200 β
ββββββββββββ¬ββββββββββββββββββββ
β
ββββββββββββΌββββββββββββββββββββ
β Kubernetes Cluster β
β βββββββββ΄βββββββββ β
β β NodePort Serviceβ β
β βββββββββ¬βββββββββ β
β ββββββ΄βββββ β
β βΌ βΌ β
β Pod-1 Pod-2 β
ββββββββββββββββββββββββββββββββ
LoadBalancer creates a NodePort + Cloud LB automatically
Creating a LoadBalancer Service
apiVersion: v1
kind: Service
metadata:
name: my-web-service
annotations:
# AWS-specific annotations
service.beta.kubernetes.io/aws-load-balancer-type: nlb
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
spec:
type: LoadBalancer
selector:
app: web
ports:
- protocol: TCP
port: 80
targetPort: 8080
# Optional: restrict to specific IPs
loadBalancerSourceRanges:
- "10.0.0.0/8"
annotations β Cloud-specific configuration. These tell the cloud provider how to configure the load balancer.
loadBalancerSourceRanges β Restrict which IP addresses can access the service.
Internal vs External Load Balancers
# External (default) β accessible from the internet
spec:
type: LoadBalancer
# Internal β only accessible within your VPC/network
spec:
type: LoadBalancer
annotations:
# AWS
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
# GCP
cloud.google.com/load-balancer-type: Internal
# Azure
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
Limitations of LoadBalancer
One LB per Service β Every LoadBalancer Service creates a separate load balancer. This gets expensive quickly.
No HTTP routing β Cannot route based on URL path or hostname.
No SSL termination β Handles TCP, not HTTP-level concerns.
Use Ingress to solve these problems β it shares a single load balancer across multiple Services with HTTP routing.