A guide explaining how to set up and configure a Vultr Load Balancer for distributing traffic across multiple servers.
Vultr Load Balancer efficiently distributes incoming traffic across multiple servers, ensuring balanced resource utilization and enhanced reliability. This service prevents individual servers from becoming overloaded by managing traffic evenly, which helps maintain application performance and uptime. By provisioning a Load Balancer, you can enhance the scalability and resilience of your applications, improving overall user experience.
Follow this guide to provision a Vultr Load Balancer on your Vultr account using the Vultr Customer Portal, API, CLI, or Terraform.
Navigate to Products and click Load Balancers.
Click Create Load Balancer.
In Load Balancer Basics, set:
Configure additional settings:
Under Health Checks, set Protocol, Port, Path, and Health Check Intervals.
In Locations, select one or more deployment locations.
In Load Balancer Configuration, expand sections as needed:
Click Create Load Balancer.
Send a GET
request to the List Regions endpoint and note your target region ID.
$ curl "https://api.vultr.com/v2/regions" \
-X GET \
-H "Authorization: Bearer ${VULTR_API_KEY}"
Send a POST
request to the Create Load Balancer endpoint to provision a Load Balancer.
$ curl "https://api.vultr.com/v2/load-balancers" \
-X POST \
-H "Authorization: Bearer ${VULTR_API_KEY}" \
-H "Content-Type: application/json" \
--data '{
"region" : "{region_id}",
"balancing_algorithm" : "{roundrobin_or_leastconn}",
"ssl_redirect" : false,
"http2": false,
"http3": false,
"proxy_protocol" : false,
"timeout" : {timeout_in_seconds},
"label" : "{label}",
"nodes" : {number_of_nodes},
"health_check" : {
"protocol" : "{http_or_https_or_tcp}",
"port" : {port},
"path" : "/health",
"check_interval" : {interval_in_seconds},
"response_timeout" : {timeout_in_seconds},
"unhealthy_threshold" : {unhealthy_threshold},
"healthy_threshold" : {healthy_threshold}
},
"forwarding_rules": [
{
"frontend_protocol" : "{http_or_https_or_tcp}",
"frontend_port" : {frontend_port_number},
"backend_protocol" : "{http_or_https_or_tcp}",
"backend_port" : {backend_port_number}
}
],
"firewall_rules": [
{
"port" : {allowed_port_number},
"source" : "{source_ip_cidr}",
"ip_type" : "{v4_or_v6}"
}
],
"auto_ssl": {
"domain_zone" : "{your_domain}",
"domain_sub" : "{subdomain}"
}
}'
Visit the Create Load Balancer page to view additional attributes you can include in your request.
Send a GET
request to the List Load Balancers endpoint to list all the available Load Balancers.
$ curl "https://api.vultr.com/v2/load-balancers" \
-X GET \
-H "Authorization: Bearer ${VULTR_API_KEY}"
List all Vultr regions and note the target region ID.
$ vultr-cli regions list
Create a Load Balancer.
$ vultr-cli load-balancer create \
--region "<region_id>" \
--balancing-algorithm "<roundrobin_or_leastconn>" \
--ssl-redirect false \
--proxy-protocol false \
--response-timeout <timeout_in_seconds> \
--label "<label>" \
--nodes <number_of_nodes> \
--protocol "<http_or_https_or_tcp>" \
--port <port> \
--path "/health" \
--check-interval <interval_in_seconds> \
--healthy-threshold <healthy_threshold> \
--unhealthy-threshold <unhealthy_threshold> \
--forwarding-rules "frontend_protocol:<http_or_https_or_tcp>,frontend_port:<frontend_port_number>,backend_protocol:<http_or_https_or_tcp>,backend_port:<backend_port_number>" \
--firewall-rules "port:<allowed_port_number>,ip_type:<v4_or_v6>,source:<source_ip_cidr>"
Run vultr-cli load-balancer create --help
to view additional options you can apply when creating a Load Balancer.
List all the available Load Balancers.
$ vultr-cli load-balancer list
Ensure the Vultr Terraform provider is configured in your Terraform project.
Define the Load Balancer resource in your Terraform configuration file.
resource "vultr_load_balancer" "lb" {
region = "ewr"
label = "vultr-load-balancer"
balancing_algorithm = "roundrobin"
forwarding_rules {
frontend_protocol = "http"
frontend_port = 82
backend_protocol = "http"
backend_port = 81
}
health_check {
path = "/test"
port = 8080
protocol = "http"
response_timeout = 1
unhealthy_threshold = 2
check_interval = 3
healthy_threshold = 4
}
}
Apply the configuration and observe the following output:
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
No comments yet.