k8s-master-keepalived-haproxy负载均衡

2023-12-28

k8s-master-keepalived-haproxy负载均衡
virtual-ip-192.168.146.130

master1 192.168.146.131
master2 192.168.146.132
master3 192.168.146.133

6443

1、yum -y install keepalived haproxy
##################################################
2、/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id 51
script_user root
enable_script_security
}
vrrp_script chk_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 5
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
mcast_src_ip 192.168.146.133
virtual_router_id 51
priority 100
advert_int 2
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.146.130 dev ens33
}
track_script {
chk_apiserver
}
}
##################################################
3、/etc/haproxy/haproxy.cfg

listen kube-master
bind *:8443
mode tcp
option tcplog
balance source
server master1 192.168.146.131:6443 check inter 2000 fall 2 rise 2 weight 1
server master2 192.168.146.132:6443 check inter 2000 fall 2 rise 2 weight 1
server master3 192.168.146.133:6443 check inter 2000 fall 2 rise 2 weight 1
4、
/etc/keepalived/check_apiserver.sh
#!/bin/bash
err=0
for k in $(seq 1 3)
do
check_code=$(pgrep haproxy)
echo $check_code
if [[ $check_code == "" ]]; then
err=$(expr $err + 1)
sleep 1
continue
else
err=0
break
fi
done

if [[ $err != "0" ]]; then
echo "systemctl stop keepalived"
/usr/bin/systemctl stop keepalived
exit 1
else
exit 0
fi

5 4kubeadm-init.txt
#--cri-socket unix:///var/run/cri-dockerd.sock \
ver=v1.28.2

IP=$(hostname -I|awk '{print $1}')
kubeadm init \
--control-plane-endpoint "192.168.146.130:8443" \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version=${ver} \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/16 \
--token "abcdef.0123456789abcdef" \
--token-ttl "0" \
--ignore-preflight-errors=Swap \
--cri-socket unix:///var/run/containerd/containerd.sock \
--v=5 |tee init.out

6、 kubeadm join 192.168.146.130:8443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:8847176e051a69858a1f372f6a9f2c6a8c65084363b6c9a5543062e8e3d9eeef \
--control-plane

分类:Linux | 标签: |

相关日志

评论被关闭!