三、安装、配置keepalived(主节点)
3.1:安装keepalived(01、02、03节点)
yum install -y keepalived
systemctl enable keepalived
node01的keepalived.conf
cat <<EOF > /etc/keepalived/keepalived.conf
global_defs {
router_id LVS_k8s
}
vrrp_script CheckK8sMaster {
script "curl -k https://10.8.1.105:6443"
interval 3
timeout 9
fall 2
rise 2
}
vrrp_instance VI_1 {
state MASTER
interface ens3
virtual_router_id 61
priority 100
advert_int 1
mcast_src_ip 10.8.1.101
nopreempt
authentication {
auth_type PASS
auth_pass sqP05dQgMSlzrxHj
}
unicast_peer {
10.8.1.102
10.8.1.103
}
virtual_ipaddress {
10.8.1.105/24
}
track_script {
CheckK8sMaster
}
}
EOF
node02的keepalived.conf
cat <<EOF > /etc/keepalived/keepalived.conf
global_defs {
router_id LVS_k8s
}
global_defs {
router_id LVS_k8s
}
vrrp_script CheckK8sMaster {
script "curl -k https://10.8.1.105:6443"
interval 3
timeout 9
fall 2
rise 2
}
vrrp_instance VI_1 {
state BACKUP
interface ens3
virtual_router_id 61
priority 90
advert_int 1
mcast_src_ip 10.8.1.102
nopreempt
authentication {
auth_type PASS
auth_pass sqP05dQgMSlzrxHj
}
unicast_peer {
10.8.1.101
10.8.1.103
}
virtual_ipaddress {
10.8.1.105/24
}
track_script {
CheckK8sMaster
}
}
EOF
node03的keepalived.conf
cat <<EOF > /etc/keepalived/keepalived.conf
global_defs {
router_id LVS_k8s
}
global_defs {
router_id LVS_k8s
}
vrrp_script CheckK8sMaster {
script "curl -k https://10.8.1.105:6443"
interval 3
timeout 9
fall 2
rise 2
}
vrrp_instance VI_1 {
state BACKUP
interface ens3
virtual_router_id 61
priority 80
advert_int 1
mcast_src_ip 10.8.1.103
nopreempt
authentication {
auth_type PASS
auth_pass sqP05dQgMSlzrxHj
}
unicast_peer {
10.8.1.101
10.8.1.102
}
virtual_ipaddress {
10.8.1.105/24
}
track_script {
CheckK8sMaster
}
}
EOF
3.2:启动keepalived
systemctl restart keepalived
可以看到虚拟IP已经绑定到node01的网卡上了
精彩评论