一文学会k8s多master集群+keepalived高可用实战

一、概述

Apiserver是 kubernetes 集群交互的入口,封装了核心对象的增删改查操作,提供了 RESTFul 风格的 API 接口,通过etcd来实现持久化并维护对象的一致性。所以在整个K8S集群中,Apiserver服务至关重要,一旦宕机,整个K8S平台将无法使用,所以保障企业高可用是运维必备的工作之一。

二、安装keepalived

1.安装keepalived

yum install keepalived.x86_64

2.修改配置

cd /etc/keepalived/
vi keepalived.conf
  • 修改master1配置文件keepalived.conf
global_defs {
 router_id keepalive-master
}

vrrp_script check_apiserver {
 # 检测脚本路径
 script "/etc/keepalived/check-apiserver.sh"
 # 多少秒检测一次
 interval 3
 # 失败的话权重-2
 weight -2
}

vrrp_instance VI-kube-master {
   state MASTER  # 定义节点角色
   interface eth0 # 网卡名称
   virtual_router_id 68
   priority 100
   dont_track_primary
   advert_int 3
   virtual_ipaddress {
     # 自定义虚拟ip
     192.168.1.199
   }
   track_script {
       check_apiserver
   }
}
  • 修改master2配置文件keepalived.conf
global_defs {
 router_id keepalive-master
}

vrrp_script check_apiserver {
 # 检测脚本路径
 script "/etc/keepalived/check-apiserver.sh"
 # 多少秒检测一次
 interval 3
 # 失败的话权重-2
 weight -2
}

vrrp_instance VI-kube-master {
   state BACKUP  # 定义节点角色
   interface eth0  # 网卡名称
   virtual_router_id 68
   priority 99
   dont_track_primary
   advert_int 3
   virtual_ipaddress {
     # 自定义虚拟ip
     192.168.1.199
   }
   track_script {
       check_apiserver
   }
}
  • 修改master3配置文件keepalived.conf
global_defs {
 router_id keepalive-master
}

vrrp_script check_apiserver {
 # 检测脚本路径
 script "/etc/keepalived/check-apiserver.sh"
 # 多少秒检测一次
 interval 3
 # 失败的话权重-2
 weight -2
}

vrrp_instance VI-kube-master {
   state BACKUP  # 定义节点角色
   interface eth0  # 网卡名称
   virtual_router_id 68
   priority 99
   dont_track_primary
   advert_int 3
   virtual_ipaddress {
     # 自定义虚拟ip
     192.168.1.199
   }
   track_script {
       check_apiserver
   }
}

3.重启keepalived

systemctl start keepalived.service

systemctl status keepalived.service
虚拟vip出现在网卡上

版权声明:
作者:siwei
链接:https://www.techfm.club/p/44680.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>