Keepalived enables a single, shared virtual IP to access our service on Docker Swarm. This eliminates the need to target individual nodes and instead allows us to target one virtual IP that is self-healing and highly available. By doing so, we no longer require an external load balancer.
Our layout:
- node1 – 10.0.0.21
- node2 – 10.0.0.22
- node3 – 10.0.0.23
- Ingress (virtual IP – Keepalived) – 10.0.0.20
Install Keepalived
On every node:
apt-get -y install keepalived
On node1 create file /etc/keepalived/keepalived.conf
global_defs {
router_id DOCKER_INGRESS
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass mypassword
}
virtual_ipaddress {
10.0.0.20
}
}
Keepalived configuration file consists of various parameters that define how the virtual IP address should be managed and maintained in a high availability environment.
On node2 same file /etc/keepalived/keepalived.conf
global_defs {
router_id DOCKER_INGRESS
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass mypassword
}
virtual_ipaddress {
10.0.0.20
}
}
We only changed two things:
- state to BACKUP
- priority to 90 from 100
On node3 same file /etc/keepalived/keepalived.conf
global_defs {
router_id DOCKER_INGRESS
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass mypassword
}
virtual_ipaddress {
10.0.0.20
}
}
Start and enabled the service to start at boot on every node (start from Node 1)
systemctl start keepalived
systemctl enable keepalived
Check
To check if keepalived successfully negotiated the virtual IP, ping 10.0.0.20 from any node.
Be First to Comment