kubernetes部署haproxy、keepalived为kube-apiserver做集群

也可以用nginx、keepalived做负载均衡,看大家的需求。

# yum -y install haproxy keepalived

haproxy的配置文件(三台一样):

cat > /etc/haproxy/haproxy.cfg <<EOF
global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /var/run/haproxy-admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon
    nbproc 1

defaults
    log     global
    timeout connect 5000
    timeout client  10m
    timeout server  10m

listen  admin_stats
    bind 0.0.0.0:10080
    mode http
    log 127.0.0.1 local0 err
    stats refresh 30s
    stats uri /status
    stats realm welcome login\ Haproxy
    stats auth admin:123456
    stats hide-version
    stats admin if TRUE

listen kube-master
    bind 0.0.0.0:8443
    mode tcp
    option tcplog
    balance source
    server 192.168.111.10 192.168.111.10:6443 check inter 2000 fall 2 rise 2 weight 1
    server 192.168.111.11 192.168.111.11:6443 check inter 2000 fall 2 rise 2 weight 1
    server 192.168.111.12 192.168.111.12:6443 check inter 2000 fall 2 rise 2 weight 1
EOF

启动haproxy:

# for SERVICES in haproxy;do systemctl enable $SERVICES; systemctl restart  $SERVICES; systemctl status $SERVICES; done

keepalived配置文件(1主):

cat > /etc/keepalived/keepalived.conf <<EOF
global_defs {
    router_id lb-master-105
}

vrrp_script check-haproxy {
    script "killall -0 haproxy"
    interval 5
    weight -30
}

vrrp_instance VI-kube-master {
    state MASTER
    priority 120
    dont_track_primary
    interface ens33
    virtual_router_id 68
    advert_int 3
    track_script {
        check-haproxy
    }
    virtual_ipaddress {
        192.168.111.9
    }
}
EOF

keepalived配置文件(2备):

cat > /etc/keepalived/keepalived.conf <<EOF
global_defs {
    router_id lb-backup-105
}

vrrp_script check-haproxy {
    script "killall -0 haproxy"
    interval 5
    weight -30
}

vrrp_instance VI-kube-master {
    state BACKUP
    priority 110
    dont_track_primary
    interface ens33
    virtual_router_id 68
    advert_int 3
    track_script {
        check-haproxy
    }
    virtual_ipaddress {
        192.168.111.9
    }
}
EOF

启动keepalived:

for SERVICES in keepalived;do systemctl enable $SERVICES; systemctl restart  $SERVICES; systemctl status $SERVICES; done

转载于:https://www.cnblogs.com/xuyingzhong/p/9761490.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值