Kubernetes 运维 - 高可用集群方案
一、概述
Keepalived
用于提供 kube-apiserver
对外服务的 VIP
地址
Haproxy
用于监听 VIP
地址,后端连接所有 kube-apiserver
实例,提供监控检查和负载均衡功能
keepalived在运行过程中对本机的haproxy进行状态进行周期性检查,如果检测到haproxy进程异常,则触发重新选主的过程,VIP也将漂移到新选出来的节点上,从而实现VIP的高可用
二、搭建负载均衡高可用
节点名 | IP地址 | 使用端口 | K8S版本 |
---|---|---|---|
master-01 | 192.168.0.10 | HA(8443) | 1.18.2 |
master-02 | 192.168.0.20 | HA(8443) | 1.18.2 |
master-03 | 192.168.0.30 | HA(8443) | 1.18.2 |
1.1 基础环境
1.1.1 配置Hosts文件
192.168.0.10 master-01
192.168.0.20 master-02
192.168.0.30 master-03
1.1.2 配置互信(可选)
ssh-keygen -t rsa
ssh-copy-id 节点名
1.1.3 系统优化
① 关闭防火墙&selinux&swap分区&iptables
systemctl stop firewalld && systemctl disable firewalld
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
yum -y install iptables-services
systemctl start iptables && systemctl enable iptables
iptables -F && service iptables save
② 优化内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
cat <<EOF > /etc/sysctl.conf
fs.aio-max-nr=1065535
kernel.pid_max=600000
net.ipv4.tcp_max_syn_backlog=30000
net.core.somaxconn=65535
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_timestamps=1
net.ipv4.ip_forward=1
net.ipv4.ip_local_reserved_ports=30000