高可用组件安装(可选)

采用 KeepAlived HAProxy 实现高可用,所以需要安装 KeepAlived HAProxy

KeepAlived 和HAProxy 的节点可以和 Master 在同一个节点,也可以在不同的节点。

如果是在公有云搭建高可用集群,可以采用公有云的负载均衡替代 KeepAlived 和 HAProxy。

如果想要搭建只有一个 Master 节点的集群,可以不安装高可用组件。

所有 Master 节点安装 HAProxy 和 KeepAlived:

yum install -y keepalived haproxy

所有 Master 节点配置 HAProxy

所有 Master 节点的 HAProxy 配置相同。

vim /etc/haproxy/haproxy.cfg 
haproxy.cfg
global
    maxconn 2000 
    ulimit-n 16384
    log 127.0.0.1 local0 err 
    stats timeout 30s
defaults 
    log global 
    mode http 
    option httplog 
    timeout connect 5000 
    timeout client 50000 
    timeout server 50000 
    timeout http-request 15s 
    timeout http-keep-alive 15s 

frontend monitor-in
    bind *:33305 
    mode http 
    option httplog 
    monitor-uri /monitor 

frontend k8s-master
    bind 0.0.0.0:16443 # 监听的端口
    bind 127.0.0.1:16443
    mode tcp 
    option tcplog
    tcp-request inspect-delay 5s 
    default_backend k8s-master 

backend k8s-master
    mode tcp 
    option tcplog 
    option tcp-check 
    balance roundrobin
    default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
    server k8s-master01 192.168.10.121:6443 check # 配置后端服务器地址
    server k8s-master02 192.168.10.124:6443 check 
    server k8s-master03 192.168.10.125:6443 check 
scp /etc/haproxy/haproxy.cfg root@k8s-master02:/etc/haproxy/haproxy.cfg
scp /etc/haproxy/haproxy.cfg root@k8s-master03:/etc/haproxy/haproxy.cfg

所有 Master 节点配置 KeepAlived

由于 KeepAlived 需要配置自身的 IP 地址和网卡名称,因此每个 KeepAlived 节点的配置不一样。

所有 Master 节点配置 KeepAlived 健康检查文件

check_apiserver.sh

启动 HAProxy 和 KeepAlived

如果是用 HAProxy 和 KeepAlived 实现的高可用,则需要测试 VIP 是否是正常的:

如果 ping 不通且 telnet 没有出现,则认为 VIP 不可用。如果 VIP 不可用,不可再继续往下执行,需要排查 VIP 的问题,比如防火墙和 SELinux、HAProxy 和 Keepalived 的状态,监听端口是否正常等。

最后更新于

这有帮助吗?