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

相关推荐
西京刀客2 小时前
Docker Desktop 替代方案之OrbStack、podman、Rancher Desktop
docker·rancher·podman·orbstack
JohnYan2 小时前
Bun技术评估 - 29 Docker集成
javascript·后端·docker
shixian10304113 小时前
Dify Docker Compose 安装指南
docker·容器·eureka
曦樂~3 小时前
【Docker】Compose
docker·容器·eureka
加上音乐3 小时前
windows—wsl2—docker配置代理以push/pull
windows·docker·容器
hour_go5 小时前
DeepHunt微服务故障定位系统核心技术解析1
微服务·云原生·架构
南方以南_5 小时前
CKA07--Argo CD
运维·kubernetes·k8s
程序员古德5 小时前
25年11月软考架构真题《论无服务器架构(Serverless)》考后复盘总结
云原生·架构·serverless
KV_T7 小时前
centos运维常用命令
linux·运维·centos