Rancher RKE 机器初始化与镜像准备

部署 Rancher + RKE 前要做的准备:拉代码、准备镜像仓库/离线镜像、centos8 系系统初始化(内核模块与 iptables/sysctl)时读这篇

02-部署安装 / 部署方式
rancher机器初始化git cloneGnuTLS离线镜像harborall_image.pypull_rancher_images.shcentos8OpenCloudOSRedhat9内核模块br_netfilteriptablesnftablessysctl

Rancher RKE 机器初始化与镜像准备

1. 机器初始化

容器运行时(Docker)安装参考《节点安装 Containerd 容器运行时》(原文指向 install/kubernetes/rancher/install_docker.md)。

clone 项目:

git clone --depth=1 https://github.com/data-infra/cube-studio.git

centos 中如果没有 git,可以先 yum install git 安装。

1.1 git clone 遇到 "GnuTLS recv error (-110)"

报错 GnuTLS recv error (-110): The TLS connection was non-properly terminated.,依次执行:

apt-get install gnutls-bin
git config --global http.sslVerify false
git config --global http.postBuffer 1048576000

再执行 git clone 即可。如果还不行,直接通过国内代理拉取:

git clone --depth=1 https://githubfast.com/data-infra/cube-studio.git

2. 建设前准备

  1. 自建 docker 镜像仓库或直接使用云厂商免费镜像仓库。如果内网无法连接互联网,可以使用 Harbor 自建内网仓库,并将私有仓库添加到 docker 的 insecure-registries 配置中。

  2. 如果内网无法连接外网,需要在机器上提前拉好镜像。修改 install/kubernetes/rancher/all_image.py 中的内网仓库地址,运行导出/推送/拉取脚本:

    • 联网机器上运行 pull_rancher_images.sh 拉取镜像并推送到内网仓库,或 rancher_image_save.sh 将镜像压缩成文件再导入到内网机器。
    • 内网(不能联网)机器上运行 pull_rancher_harbor.sh 从内网仓库中拉取镜像,或 rancher_image_load.sh 从压缩文件中导入镜像。

说明:pull_rancher_harbor.shrancher_image_save.shrancher_image_load.sh(以及 push_rancher_harbor.sh)不是仓库里的现成文件,而是运行 all_image.py 时自动生成的——先把 all_image.py 里的 harbor_repo(默认 xx.xx.xx.xx:xx/xx/)改成自己的内网仓库地址再运行。仓库里现成的脚本只有 pull_rancher_images.shreset_docker.sh。镜像清单来自 rancher-images-mini.txt。见 install/kubernetes/rancher/all_image.py:6-11

3. centos8 / centos8 stream / OpenCloudOS Server 8 / Redhat 9 系统初始化

# 修改 /etc/firewalld/firewalld.conf
# FirewallBackend=nftables
# FirewallBackend=iptables

yum install -y yum-utils device-mapper-persistent-data lvm2
yum install -y iptables container-selinux iptables-services

# 加载内核模块(写入开机自启)
(
cat << EOF

systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables
systemctl disable iptables
systemctl stop ip6tables
systemctl disable ip6tables
systemctl stop nftables
systemctl disable nftables

modprobe br_netfilter
modprobe ip_tables
modprobe iptable_nat
modprobe iptable_filter
modprobe iptable_mangle
modprobe ip6_tables
modprobe ip6table_nat
modprobe ip6table_filter
modprobe ip6table_mangle

EOF
)>>  /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
sh /etc/rc.d/rc.local

# 查看加载的内核模块
lsmod
sudo echo 'ip_tables' >> /etc/modules

systemctl status iptables
systemctl status ip6tables
systemctl status nftables
systemctl status firewalld

modinfo iptable_nat
modinfo ip6table_nat

echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-iptables=1" >> /etc/sysctl.conf
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables
sysctl -p

systemctl restart docker

reboot

# ipv6 相关错误可以忽略
# 查看模块:ls /lib/modules/`uname -r`/kernel/net/ipv6/netfilter/

系统准备好后,进入《部署 Rancher Server 与 K8s 集群》

最后更新 2026-06-30完整文档以官方仓库为准:GitHub Wiki