一、前提步骤
1、在各个节点执行(所有 Server 和 Agent 节点)
apt install apparmor -y
apt install curl -y
2、设置各节点Host文件(所有 Server 和 Agent 节点)
192.168.144.175 master01
192.168.144.167 master02
192.168.144.168 master03
192.168.144.169 node01
192.168.144.170 node02
3、永久禁用各节点的交换分区(所有 Server 和 Agent 节点)
swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab # 注释掉swap那一行
4、安装过程必须以 root 用户或通过 sudo 运行(所有 Server 和 Agent 节点)
5、下载镜像(所有 Server 和 Agent 节点)
mkdir /root/rke2-artifacts && cd /root/rke2-artifacts/
curl -OLs https://github.com/rancher/rke2/releases/tag/v1.31.4%2Brke2r1/rke2-images.linux-amd64.tar.zst
curl -OLs https://github.com/rancher/rke2/releases/tag/v1.31.4%2Brke2r1/rke2.linux-amd64.tar.gz
curl -OLs https://github.com/rancher/rke2/releases/tag/v1.31.4%2Brke2r1/sha256sum-amd64.txt
curl -sfL https://get.rke2.io --output install.sh
.
.
.
二、安装Master节点
1、安装Master01
mkdir /root/rke2-artifacts && cd /root/rke2-artifacts/
将镜像文件传到master01服务器的当前/root/rke2-artifacts/目录下。。。
INSTALL_RKE2_TYPE="server" INSTALL_RKE2_ARTIFACT_PATH=/root/rke2-artifacts sh install.sh
查看令牌,后期分配给其它server节点和agent节点
cat /var/lib/rancher/rke2/server/node-token
添加master01配置文件
mkdir -p /etc/rancher/rke2 && vi /etc/rancher/rke2/config.yaml
粘贴以下内容
token: K104332c6b52caf0f487b34d2bf185245c2f136bd5e79ec07f33d0378fa6ab8acfb::server:1da4a0a57ab66319ecfc9b6eb6a7776a
tls-san:
- master01
- master02
- master03
# node配置
node-name: master01 #只需要修改此处,主机名
node-taint: # 默认Server节点是可调度的,如果希望拥有一个不会运行用户工作负载的专用 control plane,则可以使用污点(taint)
- "CriticalAddonsOnly=true:NoExecute"
# 打标签
node-label:
- "node=Master"
重启master01
systemctl restart rke2-server && systemctl status rke2-server && systemctl enable rke2-server
.
.
.
2、安装Master02
mkdir /root/rke2-artifacts && cd /root/rke2-artifacts/
将镜像文件传到master02服务器的当前/root/rke2-artifacts/目录下。。。
INSTALL_RKE2_TYPE="server" INSTALL_RKE2_ARTIFACT_PATH=/root/rke2-artifacts sh install.sh
添加master02配置文件
mkdir -p /etc/rancher/rke2 && vi /etc/rancher/rke2/config.yaml
粘贴以下内容
server: https://master01:9345
token: K104332c6b52caf0f487b34d2bf185245c2f136bd5e79ec07f33d0378fa6ab8acfb::server:1da4a0a57ab66319ecfc9b6eb6a7776a
tls-san:
- master01
- master02
- master03
# node配置
node-name: master02 #主机名
node-taint: # 默认Server节点是可调度的,如果希望拥有一个不会运行用户工作负载的专用 control plane,则可以使用污点(taint)
- "CriticalAddonsOnly=true:NoExecute"
# 打标签
node-label:
- "node=Master"
重启master02
systemctl start rke2-server && systemctl enable rke2-server && systemctl status rke2-server
.
.
.
3、安装Master03
mkdir /root/rke2-artifacts && cd /root/rke2-artifacts/
将镜像文件传到master03服务器的当前/root/rke2-artifacts/目录下。。。
INSTALL_RKE2_TYPE="server" INSTALL_RKE2_ARTIFACT_PATH=/root/rke2-artifacts sh install.sh
添加master03配置文件
mkdir -p /etc/rancher/rke2 && vi /etc/rancher/rke2/config.yaml
粘贴以下内容
server: https://master01:9345
token: K104332c6b52caf0f487b34d2bf185245c2f136bd5e79ec07f33d0378fa6ab8acfb::server:1da4a0a57ab66319ecfc9b6eb6a7776a
tls-san:
- master01
- master02
- master03
# node配置
node-name: master03 #主机名
node-taint: # 默认Server节点是可调度的,如果希望拥有一个不会运行用户工作负载的专用 control plane,则可以使用污点(taint)
- "CriticalAddonsOnly=true:NoExecute"
# 打标签
node-label:
- "node=Master"
重启master03
systemctl start rke2-server && systemctl enable rke2-server && systemctl status rke2-server
.
.
.
三、安装Node节点
1、安装Node01
mkdir /root/rke2-artifacts && cd /root/rke2-artifacts/
将镜像文件传到node01服务器的当前/root/rke2-artifacts/目录下。。。
INSTALL_RKE2_TYPE="agent" INSTALL_RKE2_ARTIFACT_PATH=/root/rke2-artifacts sh install.sh
添加node01配置文件
mkdir -p /etc/rancher/rke2 && vi /etc/rancher/rke2/config.yaml
粘贴以下内容
server: https://master01:9345
token: K104332c6b52caf0f487b34d2bf185245c2f136bd5e79ec07f33d0378fa6ab8acfb::server:1da4a0a57ab66319ecfc9b6eb6a7776a
# node配置
node-name: node01 #主机名
重启node01
systemctl start rke2-agent && systemctl enable rke2-agent && systemctl status rke2-agent
.
.
.
2、安装Node02
mkdir /root/rke2-artifacts && cd /root/rke2-artifacts/
将镜像文件传到node02服务器的当前/root/rke2-artifacts/目录下。。。
INSTALL_RKE2_TYPE="agent" INSTALL_RKE2_ARTIFACT_PATH=/root/rke2-artifacts sh install.sh
添加node02配置文件
mkdir -p /etc/rancher/rke2 && vi /etc/rancher/rke2/config.yaml
粘贴以下内容
server: https://master01:9345
token: K104332c6b52caf0f487b34d2bf185245c2f136bd5e79ec07f33d0378fa6ab8acfb::server:1da4a0a57ab66319ecfc9b6eb6a7776a
# node配置
node-name: node02 #主机名
重启node02
systemctl start rke2-agent && systemctl enable rke2-agent && systemctl status rke2-agent
.
.
.
四、集群访问(Server1节点操作),初始化的一些操作
1、配置集群访问
mkdir -p ~/.kube && ln -s /etc/rancher/rke2/rke2.yaml ~/.kube/config && chmod 600 ~/.kube/config
ln -s /var/lib/rancher/rke2/agent/etc/crictl.yaml /etc/crictl.yaml
vi /etc/profile # 编辑该文件,并在最后行下面添加如下内容
export PATH=$PATH:/var/lib/rancher/rke2/bin
source /etc/profile
2、查看集群
kubectl get nodes
正确显示结果则部署成功。
五、卸载
执行命令
/usr/local/bin/rke2-uninstall.sh