Kontena Load Balancers are used to distribute traffic between containerized services. Therefore, having a full-featured, high-performance and reliable load balancer is one of the most essential components for building applications composed of multiple services. But when you want to route traffic to nodes from the outside world some external Load Balancers are needed.
DigitalOcean Load Balancers are a fully-managed, highly available service that distribute traffic to pools of Droplets. Providing a stable interface with automatic failover, Load Balancers accept incoming traffic and divide it among backend servers which handle the requests. That sounds an ideal solution to use with Kontena. Next we will show how to setup a DigitalOcean Load Balancer and use it together with a Kontena Load Balancer in order to have a High-Availability setup.
Setting up Kontena Load Balancers
At this point we expect that you have already setup Kontena Grid to DigitalOcean so that each node is on the same region. DigitalOcean Load Balancers can distribute traffic only to droplets that are in the same region.
First we are going to deploy a Kontena Load Balancer to every node in the grid and expose port 80 to the outside world. We can define it in a Kontena Stack file (kontena.yml)
stack: loadbalancer description: Kontena Loadbalancer version: 0.1.0 services: lb: image: kontena/lb:latest ports: - 80:80 deploy: strategy: daemon wait_for_port: 80 interval: 7d # re-deploy once in a week for security updates health_check: protocol: http port: 80 uri: /__health environment: - KONTENA_LB_HEALTH_URI=/__health
strategy: daemon deployment option Kontena will schedule one instance automatically to every node in the grid.
What is important is that we define the Health check uri for the Load Balancer and define the health check option using that uri. Health checks are used both internally and externally. Internally Kontena will re-deploy automatically all unhealthy instances. And externally monitoring tools can poll the health check uri. For example in this case we will use this when setting up DigitalOcean Load Balancer.
We can deploy this Load Balancer stack easily with:
$ kontena stack install
After it is deployed we can verify with Kontena CLI that it's up and running and listening port 80 (we have two nodes in our cluster):
Setting up DigitalOcean Load Balancer
Next we can start configuring DigitalOcean Load Balancer. It will happen in DigitalOcean Config panel:
Basically we just give it some name and select the droplets we want to use and define forwarding rules
In Advanced Settings we have to set
__health as Health check Path. It's the same path we configured health check uri for Kontena Load Balancer.
After that we can click the Create button and wait the Load Balancer is created:
Now DigitalOcean Load Balancer is distributing traffic to the Kontena Grid and we can configure our application to use Kontena Load Balancers. Then we can just point our domain name to the IP address of the DigitalOcean Load Balancer. And verify in the browser that our application is responding with the domain name:
Want to learn about real life use cases of Kontena, case studies, best practices, tips & tricks? Need some help with your project? Want to contribute to a project or help other people? Join Kontena Forum to discuss more about Kontena Platform, chat with other happy developers on our Slack discussion channel or meet people in person at one of our Meetup groups located all around the world. Check Kontena Community for more details.