使用Rancher快速部署K8S集群

原文链接

1、安装要求

在开始之前,部署Kubernetes集群机器需要满足以下几个条件:

(1)一台或多台机器,操作系统 CentOS7.x-86_x64 (2)硬件配置:2GB或更多RAM,2个CPU或更多CPU,硬盘30GB或更多 (3)可以访问外网,需要拉取镜像,如果服务器不能上网,需要提前下载镜像并导入节点 (4)禁止swap分区

2、准备环境

角色 IP 用途 k8s-master 192.168.1.76 master节点 k8s-node01 192.168.1.77 node节点 k8s-node02 192.168.1.78 node节点 k8s-server 192.168.1.79 rancher-server节点 以下操作在全部节点进行:

复制代码
# 关闭防火墙
systemctl stop firewalld
# 禁用防火墙
systemctl disable firewalld
​
# 关闭selinux
setenforce 0  # 临时
sed -i 's/enforcing/disabled/' /etc/selinux/config  # 永久
​
# 关闭swap
swapoff -a  # 临时
sed -ri 's/.*swap.*/#&/' /etc/fstab    # 永久  关闭后需要重启服务器
​
# 根据规划设置主机名
hostnamectl set-hostname <hostname>
​
# 在master添加hosts
cat >> /etc/hosts << EOF
192.168.1.76 k8s-master
192.168.1.77 k8s-node01
192.168.1.78 k8s-node02
192.168.1.79 k8s-server
EOF
​
# 将桥接的IPv4流量传递到iptables的链
vim /etc/sysctl.conf
​
cat > /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system # 生效
# 时间同步
yum install ntpdate -y
ntpdate time.windows.com
3、安装rancher
(1)安装docker
(2)启动rancher(k8s-rancher-server)
复制代码
mkdir -p /data/rancher2.7.9
docker run -d --privileged -p 80:80 -p 443:443 -v /data/rancher2.7.9:/var/lib/rancher --restart=always --name rancher2.7.9 rancher/rancher:v2.7.9
(3)访问https://192.168.1.79,设置admin的用户密码,最低12位
(4)创建集群

(4.1)选择自定义集群

(4.2)基本信息

(4.3)镜像仓库改为阿里云仓库:(registry.cn-hangzhou.aliyuncs.com)

(4.4)点击创建

(4.5)注册master节点(如果有多个master节点,就在多台机器执行)

角色全选

复制注册命令到master主机执行:

复制代码
curl --insecure -fL https://192.168.1.79/system-agent-install.sh | sudo  sh -s - --server https://192.168.1.79 --label 'cattle.io/os=linux' --token pdkmztsfkm85hp7p7nqw2972sthx2wvpj7b9fdnrzjqwbhgj7w4t2s --ca-checksum 958c7a62f60588911644492bc6d0b00691388984419144352a3d275cd708af42 --etcd --controlplane --worker

(4.6)注册worker节点,并复制脚本到worker主机执行

由于采用VMW虚拟机做集群,机器性能受限,节点一个一个加入,等待时间较长,配置日志如下:

复制代码
[INFO ] waiting for at least one control plane, etcd, and worker node to be registered
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for agent to check in and apply initial plan
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, etcd, kube-apiserver, kube-controller-manager, kube-scheduler, kubelet
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, etcd, kube-apiserver, kube-controller-manager, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, kube-apiserver, kube-controller-manager, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, kube-apiserver, kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for cluster agent to connect
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for cluster agent to connect
[INFO ] non-ready bootstrap machine(s) custom-d067344f626e and join url to be available on bootstrap node
[INFO ] provisioning done
[INFO ] configuring worker node(s) custom-9dde9a1c00dd: waiting for control plane to be available
[INFO ] configuring worker node(s) custom-9dde9a1c00dd: waiting for agent to check in and apply initial plan
[INFO ] configuring worker node(s) custom-9dde9a1c00dd: waiting for probes: calico, kubelet
[INFO ] configuring worker node(s) custom-9dde9a1c00dd: waiting for probes: calico
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-apiserver
[INFO ] configuring worker node(s) custom-9dde9a1c00dd: waiting for probes: calico
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: etcd, kube-apiserver
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: etcd, kube-apiserver, kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: etcd, kube-apiserver, kube-controller-manager, kube-scheduler
[INFO ] custom-d067344f626e
[INFO ] configuring worker node(s) custom-9dde9a1c00dd: waiting for probes: calico
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-apiserver
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-apiserver, kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-controller-manager, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: Node condition Ready is False., waiting for probes: kube-controller-manager, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: Node condition Ready is False., waiting for probes: kube-controller-manager, kube-scheduler, kubelet
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-controller-manager, kube-scheduler, kubelet
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-controller-manager, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-controller-manager
[INFO ] configuring worker node(s) custom-9dde9a1c00dd: waiting for probes: calico
[INFO ] provisioning done
[INFO ] configuring worker node(s) custom-35b45afe977c: waiting for agent to check in and apply initial plan
[INFO ] configuring worker node(s) custom-35b45afe977c: waiting for probes: calico, kubelet
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for cluster agent to connect
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, etcd, kube-apiserver, kube-controller-manager, kube-scheduler, kubelet
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, etcd, kube-apiserver, kube-controller-manager, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, kube-apiserver, kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico, kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: calico
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for cluster agent to connect
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: etcd, kube-apiserver
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: etcd, kube-apiserver, kube-controller-manager, kube-scheduler
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-apiserver, kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for probes: kube-controller-manager
[INFO ] configuring bootstrap node(s) custom-d067344f626e: waiting for cluster agent to connect
[INFO ] configuring worker node(s) custom-35b45afe977c: waiting for probes: calico, kubelet
[INFO ] configuring worker node(s) custom-35b45afe977c,custom-9dde9a1c00dd
[INFO ] configuring worker node(s) custom-35b45afe977c: Node condition MemoryPressure is Unknown. Node condition DiskPressure is Unknown. Node condition PIDPressure is Unknown. Node condition Ready is Unknown., waiting for probes: calico, kubelet
[INFO ] configuring worker node(s) custom-35b45afe977c: waiting for probes: calico, kubelet
[INFO ] configuring worker node(s) custom-35b45afe977c: waiting for probes: calico
[INFO ] provisioning done

(4.7)搭建完成:

注意:

(1)master节点注册后一直提示:Waiting for probes: kube-controller-manager, kube-scheduler。可能是因为之前注册未成功留下的数据文件db有问题。可以:

查看RKE2服务日志:

复制代码
journalctl -u rke2-server -f

通过清理并重建 etcd 数据

注意:此操作会丢失现有集群数据,仅适用于新集群或可接受重置的场景。

停止 RKE2 服务:

复制代码
sudo systemctl stop rke2-server

备份并清理 etcd 数据目录:

复制代码
sudo mv /var/lib/rancher/rke2/server/db /var/lib/rancher/rke2/server/db.bak

重新启动服务:

复制代码
sudo systemctl start rke2-server

RKE2 会自动初始化新的 etcd 数据。

(2)worker节点注册后一直提示:Waiting for probes: calico

可以直接删除/var/lib/rancher/文件夹,然后重新进行注册。

相关推荐
csdn_aspnet12 小时前
在 Docker 容器中本地运行 SQL Server
运维·docker·容器·sqlserver
如夏倾城14 小时前
入侵检测系统(IDS)原理、部署模式与 IPS/防火墙对比
大数据·网络·人工智能·网络安全·云原生·架构·kubernetes
Z21-X15 小时前
云原生运维学习笔记:Kubernetes Volume 与 Secret 实验
运维·笔记·学习·云原生·kubernetes
分布式存储与RustFS17 小时前
桶里的文件想当目录使:用 ZeroFS 把 RustFS 挂成一棵 POSIX 树
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
java资料站17 小时前
MongoDB 3节点副本集( Docker )
mongodb·docker·eureka
分布式存储与RustFS18 小时前
向量表别堆本地盘:用 LanceDB 把数据集建在 RustFS 上
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
mengge.cloud21 小时前
Python基础保姆级!从入门到入土
开发语言·python·云原生·pygame
星落梦生21 小时前
Docker学习(11)
学习·docker·容器
万里侯1 天前
日志聚类之后别把 noise 扔掉:降噪应该改变视图,不抹掉证据
人工智能·微服务·ai·容器·k8s
byte轻骑兵2 天前
如何为你的 Web 应用添加文档编辑能力:ONLYOFFICE 文档集成实战
docker·私有化部署·系统集成·在线协作·wsl2·onlyoffice docs