k8s的master实现高可用
master高可用配置
k8s master使用keepalived生产环境下推荐使用高可用模式
keepalived安装配置
登录k8s master-1 master-2,master-3,分别修改/etc/keepalived/keepalived.conf,内容如下:
master-1: global_defs { router_id master-1 } vrrp_instance VI_1 { state MASTER interface ens160 virtual_router_id 50 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.30.200 } } master-2: global_defs { router_id master-2 } vrrp_instance VI_1 { state BACKUP interface ens160 virtual_router_id 50 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.30.200 } } master-3: global_defs { router_id master-3 } vrrp_instance VI_1 { state BACKUP interface ens160 virtual_router_id 50 priority 80 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.30.200 } }
以上需要注意的地方是192.168.30.200为虚拟IP,需要和集群处于同一个网段,且没有被配置为其它的物理机的IP,ens160为物理网卡的设备名称。
在三台master上执行以下命令启动keepalived
service keepalived start
systemctl enable keepalived
在master-1上编辑初始化配置:keepalived的情况下controlPlaneEndpoint需要制定为虚拟IP地址
vi kubeadm.conf apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration kubernetesVersion: v1.23.6 imageRepository: registry.aliyuncs.com/google_containers controlPlaneEndpoint: 192.168.30.200:6443 networking: podSubnet: 10.244.0.0/16 serviceSubnet: 10.96.0.0/12
启动初始化
kubeadm init --config kubeadm.conf
加入集群节点
节点加入集群有两种角色
1.control-plane角色 表示的是master的备用节点
2.worker角色 表示的是k8s的node
control-plane节点加入方式
登录master-2和master-3,让它们以control-node的方式加入
kubeadm join 192.168.30.200:6443 --token g55zwf.wu671xiryl2c0k7z --discovery-token-ca-cert-hash sha256:2b6c285bdd34cc5814329d5ba8cec3302d53aa925430330fb35c174565f05ad0 --control-plane
把master-1节点上的/root/.kube/下的所有文件拷贝到master-2和master-3节点的/root/.kube目录下,方便master-2和master-3也可以执行kubectl指令
worker节点加入方式
kubeadm join 192.168.30.99:6443 --token g55zwf.wu671xiryl2c0k7z --discovery-token-ca-cert-hash sha256:2b6c285bdd34cc5814329d5ba8cec3302d53aa925430330fb35c174565f05ad0
本文来自博客园,作者:不懂123,转载请注明原文链接:https://www.cnblogs.com/yxh168/p/12402963.html