Balancing between distributed sites
VK Cloud lets you create fault-tolerant applications through a geographically distributed architecture using multiple backend servers hosted in different data centers (availability zones). In the event of a failure in one of the availability zones, the infrastructure automatically redirects traffic to healthy servers in other data centers, minimizing downtime.
To implement this model, a DNS-level load balancing mechanism is used, which performs regular health checks of the servers and redirects requests to backup servers.
In this example, three VMs in different availability zones will be combined using load balancing groups of the DNS service.
-
Get access to DNS balancing by contacting technical support, if this has not been done earlier.
-
Go to the VK Cloud management console.
-
Select or create three VMs with Internet access in different availability zones.
-
Write down the external IP addresses of these VMs. In this example:
83.166.234.101;109.120.188.102;217.16.23.103.
-
For the created VMs, allow incoming traffic from the IP address
169.254.169.100/32to the specified port. This is the VK Cloud technical address used to check service availability. If a security group rule restricts access to the VM port from this address, DNS balancing will mark the VM as unavailable and will not send traffic to it. -
Create a DNS zone. In this example,
example.dns.com. -
Register your domain with a domain registrar and delegate it to the VK Cloud NS servers, if this has not been done yet. Wait for the DNS records to update: this usually takes 10–30 minutes.
-
Install the
digutility on your computer to check DNS balancing:Ubuntu, DebianRed Hat, CentOS, FedoramacOSWindows$ sudo apt update && sudo apt install dnsutils
In the DNS zone, create A records corresponding to the external IP address of each added VM.
-
For the DNS zone, create a load balancing group with the
Round Robinbalancing type. -
Add all A records available in the DNS zone to the load balancing group:
- for each record, select the
ICMPmonitoring type; - leave the other parameters at their defaults.
- for each record, select the
-
On your computer, run the command:
dignslookupfor i in {1..100}; do dig www.example.dns.com A @ns4.msc.mail.ru +short; done | sort | uniq -cExpected response:
33 83.166.234.10134 109.120.188.10233 217.16.23.103Here, the beginning of each line shows the number of requests that DNS balancing sent to each server. The response shows that balancing is working and distributes requests roughly evenly among all available servers (availability zones).
-
In the management console, stop two of the three VMs. This simulates a server failure or data center unavailability.
-
On your computer, repeat the command:
dignslookupfor i in {1..100}; do dig www.example.dns.com A @ns4.msc.mail.ru +short; done | sort | uniq -cExpected response:
100 217.16.23.103Here, the response shows that DNS balancing sends all requests to one server (availability zone) because the other two servers are unavailable.
If you no longer need the added resources, delete them: