Sign In

Curriculum 16: Services & Networking

LoadBalancer Services

12 min · 25 XP

LoadBalancer Services

A LoadBalancer Service provisions an external load balancer from your cloud provider (AWS, GCP, Azure) and assigns a public IP address to your Service. It builds on top of NodePort and ClusterIP, providing the simplest way to expose a Service to the internet.

Creating a LoadBalancer Service

apiVersion: v1
kind: Service
metadata:
  name: public-api
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
  type: LoadBalancer
  selector:
    app: api-gateway
  ports:
    - port: 443
      targetPort: 8443
      protocol: TCP
kubectl apply -f lb-service.yaml
kubectl get svc public-api --watch

The EXTERNAL-IP field initially shows <pending> while the cloud provider provisions the load balancer. After a minute or two, the external IP appears.

Checking the External IP

kubectl get svc public-api

# Output:
# NAME         TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)
# public-api   LoadBalancer   10.96.45.12    35.202.100.50    443:31245/TCP
curl https://35.202.100.50

Cloud Provider Integration

Each cloud provider supports annotations to customize load balancer behavior:

# List service details including annotations
kubectl describe svc public-api

Common customizations include internal-only load balancers, health check paths, and SSL certificate attachment.

When to Use LoadBalancer

Use LoadBalancer when you need a single service directly accessible from the internet with a dedicated IP. For multiple services sharing one IP, consider an Ingress controller instead, as each LoadBalancer Service provisions a separate cloud load balancer, which adds cost.