docker+k8skubernetesalready

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

2022-06-21  本文已影响0人  sknfie

一、概述

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

二、安装keepalived

1.安装keepalived

yum install keepalived.x86_64

2.修改配置

cd /etc/keepalived/
vi 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
   }
}
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
   }
}
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出现在网卡上
上一篇下一篇

猜你喜欢

热点阅读