Load Balancing In gitlab

How we can implement load balancing for our gitlab server and how to verify it?

What problem are you trying to solve? Load balancing and git aren’t exactly a good match.

We have setup a Gitlab CI/ CD platform on a single server with multiple Runners and executors running on a number of machines. This has been working well but doesn’t provides assurance of “high availability” due to single server model. We have been asked to create a HA environment with built in load balancing and auto fail over.

We are trying to find if we can achieve this with two Gitlab CI-CD servers running on two different machines, with a “round robin” load balancer in front of them. Users will hit URL of load balancer which will redirect them to one of the servers. Few initial question we have in mind are

• How project data and meta data will be shared between two servers?
• Can repositories and source code be shared? Or do we have to maintain two repositories of same project; one in each Gitlab server?
• Is failover feature inbuilt in Gitlab CI-CD servers? Will users active on one server be auto redirected to other server.

Has anyone tried it earlier? Or any thoughts how this can be done will be highly appreciated.

1 Like

Started thinking about the same recently.

You’d need to replicate somehow all the data (“persistence layer” is the modern term, I guess):

  • Git repos
  • PostgreSQL
  • Redis
  • Registry.

While not entirely non-achievable, this might be quite complex.
PostgreSQL and Redis are alright, but file-based data will require some network file system with syncing\locking like NFS. Then you’ll get a drop in performance.

I guess GitLab was initially designed on CM principles, and it’s consistency is managed by built-in Chef cookbooks. So if something breaks - you recover it, not discard (like you would do with modern container clustering techniques).

For Git repos I would just sync them using git commands, could be as simple as git pull from a remote host.
For Registry - built-in one is quite rough, so for serious production-like use I would switch to something dedicated, for instance jFrog Artifactory.

See also:

What version of GitLab do you use? Free community or anything else?
There are two approaches of load-balancing with GitLab: Active-Active and Active-Passive. I’d recommend the first one. You can use some ways to verify it. If you use the omnibus installation I’d suggest to use another Docker instance.
If you need more assistance contact me: tgefen at almtoolbox dot com

1 Like