Uday Docs

Uday Docs

Did You Know?

Advanced visual search system powered by Ajax

Etapa 1 – Instalando HAProxy e Keepalived para Load Balancer

Estimated reading: 3 minutes 147 views

Ambiente

  • lb1: 192.168.1.190
  • lb2: 192.168.1.191
  • VIP: 192.168.1.200 (o IP flutuante que o kubeadm vai usar)

Passo 1 – Pré-requisitos

  • Ubuntu 22.04 (ou similar)
  • Interface de rede: eth0 (verifique com ip a)
  • Acesso root ou sudo

Passo 2 – Instalar HAProxy

Execute em lb1 e lb2:

sudo apt update && sudo apt install -y haproxy

Passo 3 – Configurar o HAProxy

Em ambos (lb1 lb2):

Edite o arquivo /etc/haproxy/haproxy.cfg:

sudo nano /etc/haproxy/haproxy.cfg

Substitua o conteúdo por:

global
    log /dev/log local0
    maxconn 2000
    daemon

defaults
    log     global
    mode    tcp
    option  tcplog
    timeout connect 10s
    timeout client 1m
    timeout server 1m

frontend kubernetes-api
    bind *:6443
    default_backend kubernetes-masters

backend kubernetes-masters
    balance roundrobin
    server master1 192.168.1.201:6443 check
    server master2 192.168.1.202:6443 check

Altere os IPs 192.168.1.201 e 202 conforme o IP dos seus control planes.

Salve e reinicie o serviço:

sudo systemctl restart haproxy
sudo systemctl enable haproxy

Passo 4 – Instalar Keepalived

Execute em lb1 e lb2:

sudo apt install -y keepalived

Passo 5 – Configurar o Keepalived

Em lb1 (PRINCIPAL):

cat <<EOF | sudo tee /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass kubevip
    }
    virtual_ipaddress {
        192.168.1.200
    }
}
EOF

Em lb2 (BACKUP):

cat <<EOF | sudo tee /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass kubevip
    }
    virtual_ipaddress {
        192.168.1.200
    }
}
EOF


Substitua eth0 se o nome da sua interface for diferente (use “ip add” para conferir).

Passo 6 – Iniciar o Keepalived

Execute em ambos:

sudo systemctl restart keepalived
sudo systemctl enable keepalived

Testar o VIP

De outro host (ou mesmo do master), execute:

ping 192.168.1.200
  • Desligue o lb1 (temporariamente) e veja se o IP flutuante continua pingando via lb2.
  • Ligue de novo e veja se ele reassume.

Agora você pode iniciar instalando seu cluster kubernetes na Etapa 2 – Instalação do Cluster Kubernetes com kubeadm

Leave a Comment

Share this Doc

Etapa 1 – Instalando HAProxy e Keepalived para Load Balancer

Or copy link

CONTENTS