附024.Kubernetes_v1.18.3高可用部署架构二 (3)

Keepalived安装 [root@master01 ~]# for master_ip in ${MASTER_IPS[@]} do echo ">>> ${master_ip}" ssh root@${master_ip} "yum -y install gcc gcc-c++ make libnl libnl-devel libnfnetlink-devel openssl-devel" ssh root@${master_ip} "wget :8888/software/keepalived-2.0.20.tar.gz" ssh root@${master_ip} "tar -zxvf keepalived-2.0.20.tar.gz" ssh root@${master_ip} "cd keepalived-2.0.20/ && ./configure --sysconf=http://www.likecs.com/etc --prefix=http://www.likecs.com/usr/local/keepalived && make && make install" done

提示:如上仅需Master01节点操作,从而实现所有节点自动化安装。

创建配置文件 [root@master01 ~]# wget :8888/hakek8s.sh #拉取自动部署脚本 [root@master01 ~]# chmod u+x hakek8s.sh

[root@master01 ~]# vi hakek8s.sh

#!/bin/sh #****************************************************************# # ScriptName: hakek8s.sh # Author: xhy # Create Date: 2020-06-08 20:00 # Modify Author: xhy # Modify Date: 2020-06-15 18:15 # Version: v2 #***************************************************************# ####################################### # set variables below to create the config files, all files will create at ./config directory ####################################### # master keepalived virtual ip address export K8SHA_VIP=172.24.8.100 # master01 ip address export K8SHA_IP1=172.24.8.71 # master02 ip address export K8SHA_IP2=172.24.8.72 # master03 ip address export K8SHA_IP3=172.24.8.73 # master01 hostname export K8SHA_HOST1=master01 # master02 hostname export K8SHA_HOST2=master02 # master03 hostname export K8SHA_HOST3=master03 # master01 network interface name export K8SHA_NETINF1=eth0 # master02 network interface name export K8SHA_NETINF2=eth0 # master03 network interface name export K8SHA_NETINF3=eth0 # keepalived auth_pass config export K8SHA_KEEPALIVED_AUTH=412f7dc3bfed32194d1600c483e10ad1d # kubernetes CIDR pod subnet export K8SHA_PODCIDR=10.10.0.0 # kubernetes CIDR svc subnet export K8SHA_SVCCIDR=10.20.0.0

[root@master01 ~]# ./hakek8s.sh 
解释:如上仅需Master01节点操作。执行脚本后会生产如下配置文件清单:
执行k8s_ha.sh脚本后,会自动生成以下配置文件:

kubeadm-config.yaml:kubeadm初始化配置文件,位于当前目录

keepalived:keepalived配置文件,位于各个master节点的/etc/keepalived目录

haproxy:haproxy的配置文件,位于各个master节点的/etc/haproxy/目录

calico.yaml:calico网络组件部署文件,位于config/calico/目录

[root@master01 ~]# cat kubeadm-config.yaml #检查集群初始化配置

apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration networking: serviceSubnet: "10.20.0.0/16" #设置svc网段 podSubnet: "10.10.0.0/16" #设置Pod网段 dnsDomain: "cluster.local" kubernetesVersion: "v1.18.3" #设置安装版本 controlPlaneEndpoint: "172.24.11.254:16443" #设置相关API VIP地址 apiServer: certSANs: - master01 - master02 - master03 - 127.0.0.1 - 192.168.2.11 - 192.168.2.12 - 192.168.2.13 - 192.168.2.200 timeoutForControlPlane: 4m0s certificatesDir: "/etc/kubernetes/pki" imageRepository: "k8s.gcr.io" --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 kind: KubeProxyConfiguration featureGates: SupportIPVSProxyMode: true mode: ipvs

提示:如上仅需Master01节点操作,更多config文件参考:https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2。
此kubeadm部署初始化配置更多参考:https://pkg.go.dev/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2?tab=doc。

启动服务 [root@master01 ~]# cat /etc/keepalived/keepalived.conf [root@master01 ~]# cat /etc/keepalived/check_apiserver.sh 确认Keepalived配置 [root@master01 ~]# for master_ip in ${MASTER_IPS[@]} do echo ">>> ${master_ip}" ssh root@${master_ip} "systemctl start haproxy.service && systemctl enable haproxy.service" ssh root@${master_ip} "systemctl start keepalived.service && systemctl enable keepalived.service" ssh root@${master_ip} "systemctl status keepalived.service | grep Active" ssh root@${master_ip} "systemctl status haproxy.service | grep Active" done [root@master01 ~]# for all_ip in ${ALL_IPS[@]} do echo ">>> ${all_ip}" ssh root@${all_ip} "ping -c1 172.24.8.100" done #等待30s执行检查

提示:如上仅需Master01节点操作,从而实现所有节点自动启动服务。

初始化集群

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpgzzw.html