====== Keepalived ====== 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 ===== Requisitos ===== * Dos o más servidores que tengan una IP en la misma subred. Funciona con IPs públicas. ===== Instalacion ===== sudo apt-get update && sudo apt-get install -y keepalived ===== Configuración ===== 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: * State. Is MASTER for one and BACKUP for all other hosts, hence the virtual IP will initially be assigned to the MASTER. * Interface. Is the network interface taking part in the negotiation of the virtual IP, e.g. eth0. * Virtual_router_id. Should be the same for all keepalived cluster hosts while unique amongst all clusters in the same subnet. Many distros pre-configure its value to 51. * Priority. Should be higher on the control plane node than on the backups. Hence 101 and 100 respectively will suffice. * Auth_pass. Should be the same for all keepalived cluster hosts, e.g. 42 * Virtual_ipaddress. Is the virtual IP address negotiated between the keepalived cluster hosts. 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.