VK Cloud logo

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.

Preparation steps

  1. Get access to DNS balancing by contacting technical support, if this has not been done earlier.

  2. Go to the VK Cloud management console.

  3. Select or create three VMs with Internet access in different availability zones.

  4. Write down the external IP addresses of these VMs. In this example:

    • 83.166.234.101;
    • 109.120.188.102;
    • 217.16.23.103.
  5. For the created VMs, allow incoming traffic from the IP address 169.254.169.100/32 to 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.

  6. Create a DNS zone. In this example, example.dns.com.

  7. 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.

  8. Install the dig utility on your computer to check DNS balancing:

    $ sudo apt update && sudo apt install dnsutils

1. Add A records to the DNS zone

In the DNS zone, create A records corresponding to the external IP address of each added VM.

2. Create a load balancing group

  1. For the DNS zone, create a load balancing group with the Round Robin balancing type.

  2. Add all A records available in the DNS zone to the load balancing group:

    • for each record, select the ICMP monitoring type;
    • leave the other parameters at their defaults.

3. Verify DNS balancing

  1. On your computer, run the command:

    for i in {1..100}; do dig www.example.dns.com  A @ns4.msc.mail.ru +short; done | sort | uniq -c

    Expected response:

    33 83.166.234.10134 109.120.188.10233 217.16.23.103

    Here, 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).

  2. In the management console, stop two of the three VMs. This simulates a server failure or data center unavailability.

  3. On your computer, repeat the command:

    for i in {1..100}; do dig www.example.dns.com  A @ns4.msc.mail.ru +short; done | sort | uniq -c

    Expected response:

    100 217.16.23.103

    Here, the response shows that DNS balancing sends all requests to one server (availability zone) because the other two servers are unavailable.

Delete unused resources

If you no longer need the added resources, delete them:

  1. Delete the load balancing group.
  2. Delete the DNS zone.
  3. Delete the VMs.
Was this article helpful?