当前位置: 首页 > news >正文

使用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)选择自定义集群

image-20250328171214083

(4.2)基本信息

image-20250328171241003

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

image-20250328171344781

(4.4)点击创建

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

角色全选

image-20250328171710982

复制注册命令到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主机执行

image-20250328171915070

由于采用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)搭建完成:

image-20250328172420259

image-20250328172453179

注意:

(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/文件夹,然后重新进行注册。

http://www.dtcms.com/a/597192.html

相关文章:

  • 建立网站英文翻译数字营销沙盘大赛攻略
  • 数据结构(长期更新)第7讲:栈
  • 企业网站设计过程中wordpress 侧边栏插件
  • 【20251028】linux上面拉取仓库,以Ubuntu虚拟机为例
  • 第8节 计算机病毒概念的正式化和安全行业的兴起
  • 使用C#代码在 PDF 中创建目录
  • NAT基础原理
  • 多粒子模型--交通堵塞2
  • 用AI训练数据,预测房地产价格走势(Python版)
  • Rust:泛型
  • [CSP-X2025山东小学组T4]勇者斗恶龙
  • 基于单片机的多模式智能洗衣机设计
  • 【java阶段练习】----- 学生管理系统
  • 高校网站如何建设论文外国网站怎么做
  • portfolio做网站台州做网站需要多少钱
  • 网站名称 规则装修设计培训机构
  • Dify工作流如何用“拖拉拽”重构我们的自动化测试体系?
  • 【Docker】基础
  • AI应用开发的架构哲学:框架、平台与定制的协同(ComfyUI+cnb+云存储)
  • MySQL快速入门——索引
  • 舆情处置的技术实现:Infoseek 如何用 AI 重构 “识别 - 研判 - 处置” 全链路
  • gRPC vs RPC 高频面试题
  • 淘宝联盟推广网站怎么做什么是搜索引擎
  • 扬州住房城乡建设局网站设计画册
  • 在线视频网站a做免费下载中山精品网站建设价位
  • LangFlow 节点(Node)
  • Linux设置系统同步时间
  • 花垣网站建设一台主机做两个网站
  • 生成模型技术宇宙:从VAE到世界模型,揭示AIGC核心引擎
  • 网站建设中魔板免费扑克网站代码