Spread traffic with load balancers
Spread TCP, UDP, HTTP and HTTPS traffic across your servers. A load balancer gets its own public IPv4 and IPv6 address and sends traffic only to servers that pass their health check. TLS can end at the load balancer, with managed certificates renewed for you.
Create a load balancer
- Go to Load balancers → Create load balancer.
- Enter a Name.
- Select the Data center your servers are in. Only servers in the same data center can be targets.
- Keep LB1 unless you need more than 10,000 concurrent connections, 5 services or 25 targets.
- Keep the Round robin algorithm.
- Under Services, set the Protocol, Listen port and Destination port for each port you serve. For HTTPS, also select a certificate.
- Under Targets, keep Label selector and enter the Key and Value your servers carry in their metadata, for example
roleandweb. - Under Health check, set the Path your servers answer on.
- Click Create load balancer.
The load balancer is ready in 1 to 3 minutes. Point your domain's DNS records at the IP addresses on its page.
Services
A service listens on a public port and forwards to a port on every target.
- Each listen port takes one service per transport. A UDP service may share its port number with a TCP, HTTP or HTTPS service.
- Ports 8402 and 9901 are reserved as listen ports. They're fine as destination ports.
- HTTP and HTTPS connections close after 50 seconds without data. TCP connections close after 1 hour idle.
To add a service later, click Add service on the load balancer's page.
Certificates
Each HTTPS service presents a certificate, either managed or uploaded.
- Managed certificates are issued for you, for up to 100 domains, without wildcards. Point an A or AAAA record for every domain at the load balancer's IP addresses, and the certificate is issued within minutes. It renews automatically about 30 days before it expires.
- Uploaded certificates don't renew on their own. Replace them before they expire.
Managed certificates are validated over plain HTTP on port 80. Keep port 80 free or serving HTTP. A TCP service on port 80 blocks issuance.
Targets
Targets are the servers that receive traffic. They receive it only while they pass the health check.
- Label selector picks every server in the data center whose metadata matches the key and value. Servers you create, remove or retag later join or leave within about a minute.
- Servers picks specific servers.
Select Use private IPs to reach targets over a private network they share with the load balancer.
If a label selector matches more servers than your type allows, the load balancer keeps serving its last working configuration until you narrow the selector or change the type.
Health checks
A target that fails the check several times in a row stops receiving traffic until it passes again.
HTTP and HTTPS services are checked over HTTP, and an HTTP check passes on any 2xx or 3xx status. TCP services are checked with a TCP connection.
With Round robin and Least connections, a target that stops accepting connections costs about a second of latency, not an error. Keep client timeouts above 3 seconds.
Serving UDP?
UDP services are checked over TCP or HTTP, so a check can pass while the UDP listener is broken. Point the check at something that fails together with your UDP listener, such as a daemon serving both transports on one port.
Algorithms
Source IP pins by IP address, not by user. Clients behind a rotating proxy, iCloud Private Relay or a mobile network spread across targets. When a target fails, its clients see errors for a few seconds until they move to a healthy one, while Round robin and Least connections move traffic without errors.
Changes without downtime
Adding or removing services and targets doesn't drop connections. Requests in flight finish on the old configuration, and open connections drain for up to 10 minutes.
An idle HTTP keep-alive connection is closed when a change is applied. Clients reconnect on their own, but one with retries turned off can see a failed request.
Types and limits
Connections above the type's limit wait or are refused, so the other connections keep their speed.
To change the type, click Change type on the load balancer's page, select a Type and click Change type in the dialog. Traffic stops for tens of seconds while it resizes, and a smaller type must still fit the load balancer's services, targets and certificates.
Billing
A load balancer is billed per hour from creation until removal, by type. Its public IPv4 and IPv6 addresses are included. Ingress and traffic over private networks are free. For egress, see Pricing philosophy.
Load balancers created by Kubernetes
A Kubernetes Service of type: LoadBalancer creates a load balancer for you. It's listed in Load balancers with the note Managed by Kubernetes, and it's billed as an ordinary load balancer. Change it through the Service, not the dashboard. See kubectl.
Remove a load balancer
Click Remove on the load balancer's page and confirm with Remove load balancer. Its IP addresses are released, while its private networks, firewall and certificates stay in your account.
Need help?
Please let us know at hello@betterstack.com.
We're happy to help! 🙏