The high availability mode turns several containers into a cluster that keeps the instance serving when a host fails. Before working through Enabling and deployment, prepare the nodes, containers, network and passwords. What the mode consists of is described in High availability architecture.

Hosts and containers

One cluster node is one host with one container. The mode sets no upper limit on the number of hosts. What each layer needs:

  • PostgreSQL runs on every node of the cluster: one primary server and the others standby servers. The settings floor grows with every node listed in postgresql['ha_peers'], so the replication slots fit all the standby servers.
  • Sentinel runs on three or more nodes with sentinel['quorum'] = 2. With two Sentinel nodes the quorum of 2 is never reached and a Redis failover never starts. Two hosts are therefore enough for PostgreSQL high availability but give no automatic Redis failover.
  • Gitaly and Praefect run on every node: every repository is kept on three Gitaly nodes, and when one of them fails, Praefect serves the requests from the two remaining copies.
  • The application stack — nginx, Puma, Sidekiq and the other services — runs in every container of the cluster.

The reference cluster is three identical hosts with three containers: every container runs the full stack — the application, Redis, Sentinel and PostgreSQL, with one primary server and two standby servers. The cluster survives the failure of any one node: the Sentinel quorum of 2 out of 3 is still reached, and the database either keeps running or is promoted from a surviving standby server with the commands on the Operations page. The deployment examples on Enabling and deployment use this topology. The image version and the bundled PostgreSQL major version are the same on every database node.

Container

The virtual IP addresses move between the hosts with VRRP (Virtual Router Redundancy Protocol), so the container shares the network of the host and receives the network privileges keepalived needs to manage the addresses:

docker run -d --name code \
  --network host \
  --cap-add NET_ADMIN --cap-add NET_RAW \
  --shm-size 256m \
  -e GITLAB_OMNIBUS_CONFIG="external_url 'http://<FRONTEND_VIP>'" \
  -v /srv/code/config:/etc/gitlab \
  -v /srv/code/logs:/var/log/gitlab \
  -v /srv/code/data:/var/opt/gitlab \
  <REGISTRY>/<FLAVOR>:<VERSION>

<FRONTEND_VIP> is the frontend virtual IP address for the users, described in the Network section, <REGISTRY>, <FLAVOR> and <VERSION> are the image registry, the flavor and the version of the image, as on the Quick start page.

With the host network the published ports of the single-container setup are not used: the services of the instance listen on the host network directly, and the frontend virtual IP address serves ports 80, 443 and 22 of the host. The SSH service of the container takes port 22 on every interface of the host, so before creating the container, move the SSH service of the host itself to another port, for example 2222 (the Port setting in /etc/ssh/sshd_config), and connect to the host on that port. The keepalived['interface'] value is the cluster interface of the host, and the unicast_peers addresses are the addresses of the other hosts.

Every command of the mode runs in the container through docker exec code .... Commands that ask for input run with -it.

Network

All hosts sit in one L2 network segment: the virtual IP addresses move between them with VRRP, which does not cross routers.

Multicast is not used: VRRP runs in unicast mode between the host addresses, and the keepalived processes detect each other’s availability through these VRRP packets. Allow the VRRP traffic (IP protocol 112) between the host addresses on the cluster interface.

The cluster uses two free IP addresses of the segment as virtual ones: the frontend virtual IP address for users and the database virtual IP address for PostgreSQL clients. The frontend virtual IP address is the address users open, so external_url and the TLS certificate name it.

PortWho connectsPurpose
VRRP (IP protocol 112)Every node to the other nodesThe nodes detect each other’s availability
5432Database nodes to each other, clients through the database virtual IP addressPostgreSQL: replication, peer checks, client connections
6379Redis nodes to each otherRedis replication
26379Sentinel nodes to each other, every node of the clusterSentinel monitoring and client requests
8075Praefect of every node to every Gitaly nodeGitaly: the repository storage of the cluster
2305Rails and gitlab-shell of the node, to the local Praefect onlyPraefect: routing of repository requests
80, 443, 22Users, to the frontend virtual IP address onlyThe web interface and Git over SSH

Keep port 5432 reachable from the cluster subnet only: clients must connect through the database virtual IP address, which sits on the current primary server. The database listens on all interfaces, so the database virtual IP address is always accepted — this subnet rule and the pg_hba.conf entries rendered from postgresql['md5_auth_cidr_addresses'] are what limit access to it. The web and SSH ports need no rules between the nodes: the availability of the web chain is probed locally on each node, and the nodes exchange only the VRRP packets and the database and Redis connections listed above.

Passwords

The cluster uses passwords and tokens shared by every node. Each is stored as a literal value in /etc/gitlab/gitlab.rb — the gitlab.rb file on the configuration volume, /srv/code/config/gitlab.rb on the host — and is used by the components to authenticate to each other:

PasswordUsed by
postgresql['ha_replication_password']The standby server connects to the primary server for streaming replication
postgresql['ha_check_password'] (with postgresql['ha_check_user'])Failover peer checks and the start guard
postgresql['ha_rewind_password'] (with postgresql['ha_rewind_user'])pg_rewind on the rejoin of a fenced node
redis['password']Redis replication and the application connection to Redis
The Gitaly token (the gitaly['configuration'] block)Praefect connects to the Gitaly nodes of the cluster
The Praefect token (the praefect['configuration'] block)The application and gitlab-shell connect to Praefect
The Praefect database password (the praefect['configuration'] block)Praefect connects to the praefect_production database

Pick the values with docker exec -it code gitlab-ctl pg-password-md5 <USER>: type a random secret at the prompt and use its output as the password value. Do not use whitespace, quotes or backslashes in the values: they are embedded into connection strings.

The components use the ha_* values as literal secrets. docker exec code gitlab-ctl reconfigure itself computes and stores the database-side hashes. With postgresql['sql_replication_password'] set next to postgresql['ha_replication_password'], docker exec code gitlab-ctl reconfigure fails.

Besides the passwords, two files must be identical on every node: /etc/gitlab/gitlab-secrets.json, the Rails encryption keys, and the SSH host keys. Both live on the configuration volume and are visible on the host in /srv/code/config.

Both files are copied from the first node during the deployment. The step is part of Enabling and deployment.

What is not covered

The limitations of the mode are listed in High availability architecture. The ones that affect planning: the failover is manual, a PostgreSQL major upgrade goes through a switchover, and the repositories of an instance moved from a single-node installation need a migration into the cluster layout. Backups still cover the whole instance (see Backup and restore).

Additional resources