Kubernetes apiserver 高可用

  • A+
所属分类:Kubernetes

两台master 分别安装keepalive

master01 主

master02 备

[root@master01 ~]# yum install keepalived

master01 主配置

[root@master01 ~]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id k8s-VIP
    }
   vrrp_script check_run {
    script ""curl -o /dev/null -s -w %{http_code} -k  https://192.168.20.200:6443""
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state MASTER      #master
    interface ens33  #本机物理网卡名字,可通过ip a来查看
    virtual_router_id 51
    priority 100	# 主节点权重最高 依次减少
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
   track_script {
                check_run
        }

    virtual_ipaddress {
        192.168.20.210/24
          }
}

master02  配置

[root@k8s-master02 cfg]# vim /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id k8s-VIP
}

vrrp_instance VI_1 {
    state BACKUP       #back
    interface  ens33  #本机物理网卡名字,可通过ip a来查看
    virtual_router_id 51
    priority 80		# 主节点权重最高 依次减少
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.20.210/24
          }
}

master 2节点上需要修改state为BACKUP,  (priority值必须小于master节点配置值)

启动keepalived

systemctl daemon-reload
systemctl enable keepalived
systemctl start keepalived
systemctl status keepalived

master 节点

ip add

可以看到

修改两台master的apisrver,绑定vip

[root@k8s-master02 cfg]# vim /opt/kubernetes/cfg/kube-apiserver 
--bind-address=192.168.20.200 \
--advertise-address=192.168.20.200 \

注意:客户端node节点,也需要修改配合,绑定vip

vim bootstrap.kubeconfig
vim kubelet.kubeconfig
vim kube-proxy.kubeconfig

node重启服务

systemctl restart kube-proxy
systemctl restart kubelet

最后,master重启api server测试vip漂移

YaLei

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: