how to setup a load balancer in aws for livekit se...
# ask-ai
g
how to setup a load balancer in aws for livekit self host?
t
Thanks for reaching out, Harsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to set up an AWS load balancer for a self‑hosted LiveKit deployment — here’s a concise, practical plan you can follow. 1) Use two load balancers • ALB (Application Load Balancer) for signaling/WebSocket (HTTPS) on port 443. ALB will terminate TLS (use an ACM cert) and forward to LiveKit API/WebSocket on port 7880. • NLB (Network Load Balancer) for media (WebRTC/ICE/TURN) to handle UDP and preserve client IPs. Forward the media ports to your LiveKit hosts. 2) Ports to route • 443 TCP → ALB → target port 7880 TCP (LiveKit API / WebSocket) • 7881 TCP → NLB → target port 7881 (ICE/TCP) • 3478 UDP → NLB → target port 3478 (STUN/TURN UDP) • 5349 TCP → NLB → target port 5349 (TURN/TLS) if using TURN/TLS via NLB • 50000–60000 UDP (or your configured port range) → NLB → same port range (ICE/UDP media) 3) TLS / certificates • Install your certificate in ACM and attach it to the ALB listener on port 443. • TURN TLS can use 5349 behind the NLB; alternatively, configure
tls_port
= 443 if you won’t front TURN with a load balancer. 4) AWS target type & networking recommendations • For EC2: register instances as targets for ALB and NLB. For Kubernetes: use NLB in instance (node) mode and run LiveKit pods with
hostNetwork: true
so pods can bind the media UDP/TCP ports. Run one LiveKit pod per node because of host port binding. • Enable preserve client source IP on the NLB if you need original client IPs. 5) Security groups and firewall • Allow inbound from ALB to instance TCP 7880. • Allow inbound from NLB to instance on TCP 7881, UDP 3478, UDP port range (50000–60000), and any TURN ports you use. • Ensure ALB and NLB security groups allow client traffic (e.g., 0.0.0.0/0 or restricted CIDR as appropriate). 6) DNS and routing • Point your domain (e.g., livekit.yourdomain.com) to the ALB DNS name (Route 53 alias). • If using multi-region or global setups, consider Route 53 latency routing or multi-region deployments and front with region-aware DNS. 7) Health checks and autoscaling • Configure ALB health checks against LiveKit’s HTTP/WebSocket endpoint (port 7880). • Configure NLB health checks for the media ports. • When autoscaling or deploying on Kubernetes, ensure graceful termination (avoid killing pods with active sessions quickly). If you want, tell me: • Are you deploying on EC2 VMs or Kubernetes (EKS)? • Which port range and TURN configuration you plan to use? I’ll provide step‑by‑step AWS console/CloudFormation or Helm suggestions tailored to your setup. Sources: Deploying LiveKit | LiveKit docs | Ports and firewall | LiveKit docs | Deploy to Kubernetes | LiveKit docs | Running LiveKit on AWS | Distributed Setup | LiveKit docs