ha high availability redundancy failover
Aplicacion para proveer de Alta Disponibilidad a dos servidores, que compartiran una direccion IP. Uno sera el activo y los demás pasivos.
Fuente: https://github.com/kubernetes/kubeadm/blob/master/docs/ha-considerations.md#keepalived-configuration
sudo apt-get update && sudo apt-get install -y keepalived
En este ejemplo la IP flotante será '8.8.8.8'.
1. Crear archivo:
sudo vim /etc/keepalived/keepalived.conf
Con el siguiente contenido:
! /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_script check_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 3
weight -2
fall 10
rise 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
authentication {
auth_type PASS
auth_pass k8s
}
virtual_ipaddress {
45.150.187.221
}
track_script {
check_apiserver
}
}
Comentarios:
2. Crear archivo:
sudo vim /etc/keepalived/check_apiserver.sh
Con el siguiente contenido:
#!/bin/sh
errorExit() {
echo "*** $*" 1>&2
exit 1
}
curl --silent --max-time 2 --insecure http://localhost/ -o /dev/null || errorExit "Error GET https://localhost/"
if ip addr | grep -q 8.8.8.8; then
curl --silent --max-time 2 --insecure http://8.8.8.8/ -o /dev/null || errorExit "Error GET http://8.8.8.8/"
fi
Reemplazar '8.8.8.8' por la IP flotante a usar.
3. Dar permisos de ejecución:
sudo chmod +x /etc/keepalived/check_apiserver.sh
4. Habilitar el servicio keepalived:
sudo systemctl enable keepalived --now
5. Repetir los pasos 1 a 4 para el resto de nodos, ajustando los valores según los comentarios de cada paso
6. Probar:
6.1. Ejecutar:
wget http://8.8.8.8
Reemplazar '8.8.8.8' por la IP flotante a usar.
6.2. Apagar el nodo que tenga la IP flotante en ese momento
6.3. Repetir el paso 6.1.