Using Azure Load Balancer to distribute UDP traffic

Contents

Introduction

In this blog post, I am describing steps to setup load balancing of UDP-based CoAP traffic using the Azure Load Balancer. The resulting architecture looks like depicted below:

From the short video below, you can see how I tested the end result. This was done by generating CoAP traffic from command line and expecting the response to be delivered from one of the two virtual machines that I had setup to serve the client:

From below you can read how to setup the virtual machines, configure the load balancer and finally details about how to test the result end to end.

Setting up the virtual machines

I created two Ubuntu virtual machines to the same availability set. Using an availability set is important for redundancy, but more importantly for this scenario, the availability set acts as the backend pool for the load balancer (as you can read from below).

After the virtual machines were provisioned, installed the software required by my CoAP server over an SSH connection. I used a Node.js project from https://github.com/mcollina/node-coap by referring to it in my package.json file:

In addition to running the CoAP server, the virtual machines need respond to health probes from the load balancer (so that it can be determined if the machine in question is able to handle traffic). A UDP server can’t act as health probe in itself, because UDP doesn’t have acknowledgements that the load balancer could check so an additional component is needed.

A simple way to handle health probes in this test scenario is to start a TCP server on the virtual machines that just accepts TCP connections and can be used to check that the machine is up. I achieved this with the following command:

netcat -lk 5683

Above starts a TCP server in the Ubuntu virtual machine which keeps on accepting TCP connections in port 5683.

To make the CoAP traffic and the health probe traffic flow to the virtual machines, I assigned the following network security rules: