附031.Kubernetes_v1.20.4高可用部署架构二 (2)

kubeadm不能安装或管理 kubelet 或 kubectl ,所以得保证他们满足通过 kubeadm 安装的 Kubernetes控制层对版本的要求。如果版本没有满足要求,可能导致一些意外错误或问题。
具体相关组件安装见;附001.kubectl介绍及使用书

提示:Kubernetes 1.20.4版本所有兼容相应组件的版本参考:https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.20.4.md。

正式安装 [root@master01 ~]# for all_ip in ${ALL_IPS[@]} do echo ">>> ${all_ip}" ssh root@${all_ip} "cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF" ssh root@${all_ip} "yum install -y kubeadm-1.20.4-0.x86_64 kubelet-1.20.4-0.x86_64 kubectl-1.20.4-0.x86_64 --disableexcludes=kubernetes" ssh root@${all_ip} "systemctl enable kubelet" done [root@master01 ~]# yum search -y kubelet --showduplicates #查看相应版本

提示:如上仅需Master01节点操作,从而实现所有节点自动化安装,同时此时不需要启动kubelet,初始化的过程中会自动启动的,如果此时启动了会出现报错,忽略即可。

说明:同时安装了cri-tools, kubernetes-cni, socat三个依赖:
socat:kubelet的依赖;
cri-tools:即CRI(Container Runtime Interface)容器运行时接口的命令行工具。

部署高可用组件

HAProxy安装 [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 wget openssh-clients systemd-devel zlib-devel pcre-devel libnl3-devel" ssh root@${master_ip} "wget " ssh root@${master_ip} "tar -zxvf haproxy-2.3.5.tar.gz" ssh root@${master_ip} "cd haproxy-2.3.5/ && make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_ZLIB=1 USE_SYSTEMD=1 PREFIX=http://www.likecs.com/usr/local/haprpxy && make install PREFIX=http://www.likecs.com/usr/local/haproxy" ssh root@${master_ip} "cp /usr/local/haproxy/sbin/haproxy /usr/sbin/" ssh root@${master_ip} "useradd -r haproxy && usermod -G haproxy haproxy" ssh root@${master_ip} "mkdir -p /etc/haproxy && cp -r /root/haproxy-2.3.5/examples/errorfiles/ /usr/local/haproxy/" done

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

提示:如上仅需Master01节点操作,从而实现所有节点自动化安装。若出现如下报错:undefined reference to `OPENSSL_init_ssl’,可带上openssl lib路径:

LDFLAGS="$LDFAGS -L /usr/local/openssl/lib/" ./configure --sysconf=http://www.likecs.com/etc --prefix=http://www.likecs.com/usr/local/keepalived

创建配置文件 [root@master01 ~]# wget #拉取自动部署脚本 [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.16.10.254 # master01 ip address export K8SHA_IP1=172.16.10.11 # master02 ip address export K8SHA_IP2=172.16.10.12 # master03 ip address export K8SHA_IP3=172.16.10.13 # 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节点操作。执行hakek8s.sh脚本后会生产如下配置文件清单:

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

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

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

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

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