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. 建设前准备
自建 docker 镜像仓库或直接使用云厂商免费镜像仓库。如果内网无法连接互联网,可以使用 Harbor 自建内网仓库,并将私有仓库添加到 docker 的
insecure-registries配置中。如果内网无法连接外网,需要在机器上提前拉好镜像。修改
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.sh、rancher_image_save.sh、rancher_image_load.sh(以及push_rancher_harbor.sh)不是仓库里的现成文件,而是运行all_image.py时自动生成的——先把all_image.py里的harbor_repo(默认xx.xx.xx.xx:xx/xx/)改成自己的内网仓库地址再运行。仓库里现成的脚本只有pull_rancher_images.sh和reset_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 集群》。