This guide helps you to deploy a Load Balancer (HAProxy) service in a Docker container using the D2C platform. It might be helpful for beginners as well as for advanced developers.
A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Containers isolate software from its surroundings, for example, differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.
Please, check out the original Docker post about containers for a better understanding of all the benefits of the technology.
I’m going to start with a project which already has a deployed application service. If you missed that guide, check out our guides for starting the runtime you need. In my case, it is a project with a Python app deployed on three hosts.
Creating HAProxy service
At first, you need to open a service you want to balance and click “+Add load balancer“.
Creating HAProxy service. Mode
By default, for a HAProxy service D2C creates a public domain like: [servicename-lb]-[www].[accountID].[at].d2c.io. So, for a start it’s better to use HTTP or TCP mode. You can change the mode to HTTPS and add your domain after the service is deployed. We will talk about it below.
Creating HAProxy service. Ports
Access from the Internet is enabled for HAProxy by default. You can disable access from the Internet while creating or editing the service.
Creating HAProxy service. Select hosts
After successful deployment your project should look like:
At this block, you can choose what domains to use, change the mode and config of HAProxy. Click on the “Generate new config” button to make changes.
You might find helpful our previous articles about configuring HAProxy (Part one and Part Two).
The actions and behaviour are almost the same as configuring NGINX. The different are:
- HAProxy can serve only one service (NGINX can serve any amount of services)
- HAProxy has Sticky sessions mode. It can reduce the number of connections, and this is one of the ways to allow WebSockets work on multiple hosts. When you turn it on a user connects to the same host all the time: