Keepalived não encaminhará o tráfego para o nó BACKUP após a configuração do cluster Kubernetes

Keepalived não encaminhará o tráfego para o nó BACKUP após a configuração do cluster Kubernetes

Estrutura do sistema:

  • 10.10.1.86: nó mestre do Kubernetes
  • 10.10.1.87: nó do trabalhador 1 do Kubernetes; keepalivedNó MESTRE
  • 10.10.1.88: nó do trabalhador 2 do Kubernetes; keepalivedNó BACKUP
  • 10.10.1.90: VIP, carregaria o saldo para .87& .88; implementado por keepalived.

Este cluster Kubernetes é um ambiente de desenvolvimento, testando a coleta de log de netflow.

O que eu quero alcançar é:

  1. Todos os roteadores / switches netflow registram a primeira saída para.90
  2. Em seguida, use keepalivedpara balancear a carga ( lb_kind: NAT) para .87& .88, que são dois trabalhadores do Kubernetes.
  3. Existe NodePortum serviço para capturar esse tráfego no cluster Kubernetes e fazer o restante dos trabalhos de análise de dados.
  • Algo como:
        |                {OS Network}                   |   {Kubernetes Network}

                                K8s Worker -> filebeat -> logstash (deployments)
                              /
<data> -> [VIP] load balance
                              \ 
                                K8s Worker -> filebeat -> logstash (deployments)
  • filebeat.yml (testei se o tráfego está bom após o filebeat, então uso filea saída para restringir a causa raiz).
# cat filebeat.yml
filebeat.inputs:

- type: tcp
  max_message_size: 10MiB
  host: "0.0.0.0:5100"

- type: udp
  max_message_size: 10KiB
  host: "0.0.0.0:5150"




#output.logstash:
#  hosts: ["10.10.1.87:30044", "10.10.1.88:30044"]
output.file:
  path: "/tmp/"
  filename: tmp-filebeat.out

Kubernetes

  • Master e Workers são 3 VMs em meu ambiente privado; nenhum dos provedores do GCP ou AWS.
  • Versão:
# kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:31:21Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:25:06Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"linux/amd64"}
  • Serviços
# cat logstash.service.yaml
apiVersion: v1
kind: Service
metadata:
  name: logstash-service
spec:
  type: NodePort
  selector:
    app: logstash
  ports:
    - port: 9514
      name: tcp-port
      targetPort: 9514
      nodePort: 30044
  • Depois que os dados chegam ao Kubernetes, tudo funciona bem.
  • Foi o balanceamento de carga VIP que não foi encaminhado.

Configuração mantida viva

!Configuration File for keepalived
global_defs {
  router_id proxy1   # `proxy 2` at the other node
}


vrrp_instance VI_1 {
  state MASTER       # `BACKUP` at the other node
  interface ens160
  virtual_router_id 41
  priority 100       # `50` at the other node
  advert_int 1
  virtual_ipaddress {
    10.10.1.90/23
  }
}

virtual_server 10.10.1.90 5100 {
  delay_loop 30
  lb_algo rr
  lb_kind NAT
  protocol TCP
  persistence_timeout 0

  real_server 10.10.1.87 5100 {
    weight 1
  }
  real_server 10.10.1.88 5100 {
    weight 1
  }
}
virtual_server 10.10.1.90 5150 {
  delay_loop 30
  lb_algo rr
  lb_kind NAT
  protocol UDP
  persistence_timeout 0

  real_server 10.10.1.87 5150 {
    weight 1
  }
  real_server 10.10.1.88 5150 {
    weight 1
  }

Funciona antes da configuração do cluster Kubernetes

  • Ambos .87& .88instalaram keepalivede rro balanceamento de carga (RoundRobin) funciona bem (TCP e UDP).
  • Pare keepalivedo serviço ( systemctl stop keepalived) ao configurar o cluster Kubernetes, apenas para garantir.

Ocorreu um problema após a configuração do cluster Kubernetes

  • Descobriu que apenas o nó MASTER .87pode encaminhar o tráfego, o VIP não pode encaminhar para o nó BACKUP .88.
  • Os dados encaminhados do MASTER são capturados com sucesso por kubernetes NodePorte implantações.

Teste de problema por nc:

  • nc: somente quem possui VIP (nó MASTER) pode encaminhar o tráfego, quando rrencaminhar para BACKUP, apenas mostra timeout.
  • também testado nc -l 5100em ambos os servidores, apenas o nó MASTER obteve resultados.
# echo "test" | nc 10.10.1.90 5100
# echo "test" | nc 10.10.1.90 5100
Ncat: Connection timed out.
# echo "test" | nc 10.10.1.90 5100
# echo "test" | nc 10.10.1.90 5100
Ncat: Connection timed out.

Algumas informações

  • Versões do pacote
# rpm -qa |grep keepalived
keepalived-1.3.5-19.el7.x86_64
  • CNI do Kubernetes:Calico
# kubectl get pod -n kube-system
NAME                                      READY   STATUS    RESTARTS   AGE
calico-kube-controllers-b656ddcfc-wnkcj   1/1     Running   2          78d
calico-node-vnf4d                         1/1     Running   8          78d
calico-node-xgzd5                         1/1     Running   1          78d
calico-node-zt25t                         1/1     Running   8          78d
coredns-558bd4d5db-n6hnn                  1/1     Running   2          78d
coredns-558bd4d5db-zz2rb                  1/1     Running   2          78d
etcd-a86.axv.bz                           1/1     Running   2          78d
kube-apiserver-a86.axv.bz                 1/1     Running   2          78d
kube-controller-manager-a86.axv.bz        1/1     Running   2          78d
kube-proxy-ddwsr                          1/1     Running   2          78d
kube-proxy-hs4dx                          1/1     Running   3          78d
kube-proxy-qg2nq                          1/1     Running   1          78d
kube-scheduler-a86.axv.bz                 1/1     Running   2          78d
  • ipvsadm(mesmo resultado em .87, .88)
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.10.1.90:5100 rr
  -> 10.10.1.87:5100              Masq    1      0          0
  -> 10.10.1.88:5100              Masq    1      0          0
UDP  10.10.1.90:5150 rr
  -> 10.10.1.87:5150              Masq    1      0          0
  -> 10.10.1.88:5150              Masq    1      0          0
  • Selinux é semprePermissive
  • Se stop firewalld, ainda não funciona.
  • sysctldiferença:
# before:
net.ipv4.conf.all.accept_redirects = 1
net.ipv4.conf.all.forwarding = 0
net.ipv4.conf.all.route_localnet = 0
net.ipv4.conf.default.forwarding = 0
net.ipv4.conf.lo.forwarding = 0
net.ipv4.ip_forward = 0

# after
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.all.route_localnet = 1
net.ipv4.conf.default.forwarding = 1
net.ipv4.conf.lo.forwarding = 1
net.ipv4.ip_forward = 1

Não tenho certeza se alguma verificação adicional pode ser feita agora, por favor avise, obrigado!

informação relacionada