千家信息网

Sealos安装Kubernetes v1.16.0 HA集群

发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,Sealos安装Kubernetes v1.16.0 HA集群github项目链接https://github.com/fanux/sealos初始化master节点与worker节点初始化脚本 in
千家信息网最后更新 2025年01月23日Sealos安装Kubernetes v1.16.0 HA集群

Sealos安装Kubernetes v1.16.0 HA集群

github项目链接
https://github.com/fanux/sealos

初始化master节点与worker节点

初始化脚本 init.sh

#!/bin/bash# 在 master 节点和 worker 节点都要执行# 安装 docker# 参考文档如下# https://docs.docker.com/install/linux/docker-ce/centos/ # https://docs.docker.com/install/linux/linux-postinstall/# 卸载旧版本yum remove -y docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-selinux \docker-engine-selinux \docker-engine# 设置 yum repositoryyum install -y yum-utils \device-mapper-persistent-data \lvm2yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# 安装并启动 dockeryum install -y docker-ce-18.09.7 docker-ce-cli-18.09.7 containerd.iosystemctl enable dockersystemctl start docker# 安装 nfs-utils# 必须先安装 nfs-utils 才能挂载 nfs 网络存储yum install -y nfs-utils# 关闭 防火墙systemctl stop firewalldsystemctl disable firewalld# 关闭 SeLinuxsetenforce 0sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config# 关闭 swapswapoff -ayes | cp /etc/fstab /etc/fstab_bakcat /etc/fstab_bak |grep -v swap > /etc/fstab# 修改 /etc/sysctl.conf# 如果有配置,则修改sed -i "s#^net.ipv4.ip_forward.*#net.ipv4.ip_forward=1#g"  /etc/sysctl.confsed -i "s#^net.bridge.bridge-nf-call-ip6tables.*#net.bridge.bridge-nf-call-ip6tables=1#g"  /etc/sysctl.confsed -i "s#^net.bridge.bridge-nf-call-iptables.*#net.bridge.bridge-nf-call-iptables=1#g"  /etc/sysctl.conf# 可能没有,追加echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.confecho "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.confecho "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf# 执行命令以应用sysctl -p# 配置K8S的yum源cat < /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64enabled=1gpgcheck=0repo_gpgcheck=0gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgEOF# 卸载旧版本yum remove -y kubelet kubeadm kubectl# 安装kubelet、kubeadm、kubectlyum install -y kubelet-1.16.0 kubeadm-1.16.0 kubectl-1.16.0# 修改docker Cgroup Driver为systemd# # 将/usr/lib/systemd/system/docker.service文件中的这一行 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock# # 修改为 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd# 如果不修改,在添加 worker 节点时可能会碰到如下错误# [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". # Please follow the guide at https://kubernetes.io/docs/setup/cri/sed -i "s#^ExecStart=/usr/bin/dockerd.*#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd#g" /usr/lib/systemd/system/docker.service# 设置 docker 镜像,提高 docker 镜像下载速度和稳定性# 如果您访问 https://hub.docker.io 速度非常稳定,亦可以跳过这个步骤curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io# 重启 docker,并启动 kubeletsystemctl daemon-reloadsystemctl restart dockersystemctl enable kubelet && systemctl start kubeletdocker version

Sealos

# 下载sealoswget https://github.com/fanux/sealos/releases/download/v2.0.7/sealos# 加执行权限,并将sealos移至/usr/bin下chmod +x sealos && mv sealos /usr/bin

sealos选项

--master   master服务器地址列表--node     node服务器地址列表--user     服务器ssh用户名--passwd   服务器ssh用户密码--pkg-url  离线包位置,可以放在本地目录,也可以放在一个http服务器上,sealos会wget到安装目标机--version  kubernetes版本

初始化k8s HA集群

sealos init --passwd YOUR_SERVER_PASSWD    --master 172.31.194.114  --master 172.31.194.116  --master 172.31.194.115 \  --node 172.31.194.117 \  --pkg-url https://sealyun.oss-cn-beijing.aliyuncs.com/37374d999dbadb788ef0461844a70151-1.16.0/kube1.16.0.tar.gz  \   --version v1.16.0

执行完成后shell最后一行输出如下说明集群部署成功

2019-11-07 17:30:20 [INFO] [github.com/fanux/sealos/install/print.go:25] sealos install success.

我们来获取一下节点的状态

[root@master01 ~]# kubectl get nodesNAME       STATUS   ROLES    AGE   VERSIONmaster01   Ready    master   11h   v1.16.0master02   Ready    master   11h   v1.16.0master03   Ready    master   11h   v1.16.0node01     Ready       11h   v1.16.0
# 获取service[root@master01 ~]# kubectl get svcNAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGEkubernetes   ClusterIP   10.96.0.1            443/TCP   17h# 通过查看 ipvs 规则,我们可以看到发送至 10.96.0.1 的请求都被负载至所有master节点。[root@master01 ~]# ipvsadm -LnIP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  10.96.0.1:443 rr  -> 172.31.194.114:6443          Masq    1      3          0           -> 172.31.194.115:6443          Masq    1      2          0           -> 172.31.194.116:6443          Masq    1      0          0         
0