Labs ICT
⭐ Pro Login

LoadBalancer

Exposing services via a cloud provider load balancer

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.