k8s master01
$ cat /usr/local/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
! vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_apiserver {
script "/usr/local/etc/keepalived/check_master.sh"
interval 2
weight -30
}
vrrp_instance VI_1 {
state MASTER
priority 100
interface eth0
virtual_router_id 40
advert_int 1
authentication {
auth_type PASS
auth_pass 111
}
virtual_ipaddress {
192.168.1.110
}
track_script {
chk_apiserver
}
}
k8s master02
$ cat /usr/local/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
! vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_apiserver {
script "/usr/local/etc/keepalived/check_master.sh"
interval 2
weight -30
}
vrrp_instance VI_1 {
state BACKUP
priority 90
interface eth0
virtual_router_id 40
advert_int 1
authentication {
auth_type PASS
auth_pass 111
}
virtual_ipaddress {
192.168.1.110
}
track_script {
chk_apiserver
}
}
k8s master03
$ cat /usr/local/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
! vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_apiserver {
script "/usr/local/etc/keepalived/check_master.sh"
interval 2
weight -30
}
vrrp_instance VI_1 {
state BACKUP
priority 80
interface eth0
virtual_router_id 40
advert_int 1
authentication {
auth_type PASS
auth_pass 111
}
virtual_ipaddress {
192.168.1.110
}
track_script {
chk_apiserver
}
}
$ cat /usr/local/etc/keepalived/check_master.sh
#!/bin/sh
errorExit() {
echo "*** $*" 1>&2
exit 1
}
curl --silent --max-time 2 --insecure https://localhost:6443/ -o /dev/null || errorExit "Error GET https://localhost:6443/"
if ip addr | grep -q 10.12.32.7; then
curl --silent --max-time 2 --insecure https://192.168.1.110:6443/ -o /dev/null || errorExit "Error GET https://10.12.32.7:6443/"
fi
网友评论