在客户提供的虚拟机环境上安装K8S时,发现三台K8S Master上安装keepalived后,三个Master节点都出现虚拟IP,导致K8S安装失败。
正常在安装keepalived情况下,VIP只会在其中一个节点出现,并且要出现在第一个配置的Master节点,否则,整个安装将无法进行。
经分析,我们的keepalived配置使用的是nopreempt非抢占模式,通过priority权重来区分谁的优先级更高,但是这种方式需要局域网环境开启组播,而客户环境下可能是交换机禁用了组播方式,造成keepalived集群的备服务器无法收到vrrp包,无法自动组网。这种情况下,需要使用keepalived的单播模式。使用如下配置:
unicast_src_ip 10.11.111.205## 当前masterIP
unicast_peer {
10.11.111.209## 另外masterIP
10.11.111.215## 另外masterIP
}
Master1: 10.11.111.205
[root@prodk8s205 ~]# cat /etc/keepalived/keepalived.conf global_defs { router_id cosmic_k8s }
vrrp_instance VI_1 { state MASTER interface enp3s0 virtual_router_id 47 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1721 } virtual_ipaddress { 10.11.111.220 }
unicast_src_ip 10.11.111.205 unicast_peer { 10.11.111.209 10.11.111.215 }
track_script { chk_http_port } } |
Master1: 10.11.111.209
[root@prodk8s209 ~]# cat /etc/keepalived/keepalived.conf global_defs { router_id cosmic_k8s }
vrrp_instance VI_1 { state BACKUP interface enp3s0 virtual_router_id 47 priority 95 advert_int 1 authentication { auth_type PASS auth_pass 1721 } virtual_ipaddress { 10.11.111.220 }
unicast_src_ip 10.11.111.209 unicast_peer { 10.11.111.205 10.11.111.215 }
track_script { chk_http_port } } |
Master1: 10.11.111.215
[root@prodk8s215 ~]# cat /etc/keepalived/keepalived.conf global_defs { router_id cosmic_k8s }
vrrp_instance VI_1 { state BACKUP interface enp3s0 virtual_router_id 47 priority 95 advert_int 1 authentication { auth_type PASS auth_pass 1721 } virtual_ipaddress { 10.11.111.220 }
unicast_src_ip 10.11.111.215 unicast_peer { 10.11.111.209 10.11.111.205 }
track_script { chk_http_port } } |
通过service keepalived restart重启,重启后VIP就正常出现在其中一个节点上,然后在这个VIP所在的节点上开始安装K8S Master。