第 1 步系统基础环境准备关闭防火墙和 SELinuxsystemctl disable --now firewalld setenforce 0 sed -i s/^SELINUXenforcing$/SELINUXdisabled/ /etc/selinux/config2. 关闭 Swap 分区K8s 强制要求swapoff -a sed -i / swap / s/^\(.*\)$/#\1/g /etc/fstab3. 加载基础内核模块并配置网络参数cat EOF | sudo tee /etc/modules-load.d/k8s.conf overlay br_netfilter EOF modprobe overlay modprobe br_netfilter cat EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-iptables 1 net.bridge.bridge-nf-call-ip6tables 1 net.ipv4.ip_forward 1 EOF sysctl --system第2步.配置 IPVS 内核模块生产级网络准备kube-proxy 使用 IPVS 模式需要内核支持。我们提前加载好相关模块避免后续切换时找不到模块。1. 安装 ipvsadm 管理工具yum install -y ipvsadm # (如果是 Ubuntu 系统请使用 apt install -y ipvsadm)2. 临时加载 IPVS 相关的内核模块modprobe -- ip_vs modprobe -- ip_vs_rr modprobe -- ip_vs_wrr modprobe -- ip_vs_sh modprobe -- nf_conntrack3. 确保开机自动加载这些模块永久生效cat EOF | sudo tee /etc/modules-load.d/ipvs.conf ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh nf_conntrack EOF第 3 步1.安装并配置 containerdyum install -y containerd.io或下载 RPM 包到服务器请在终端执行以下命令直接从阿里云镜像下载适合麒麟 V10基于 CentOS 8的 containerd 包wget https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/Packages/containerd.io-1.6.32-3.1.el8.x86_64.rpm2. 验证文件是否下载成功ls -l containerd.io-*.rpm3.使用本地命令安装文件下载好后再执行本地安装命令sudo yum localinstall -y containerd.io-*.rpm启动 Containerdsystemctl daemon-reload systemctl enable --now containerd4.执行命令查看我们集群需要用得镜像kubeadm config images list以下就是初始化需要得镜像需要提前准备以下是提前准备得镜像可自行拉取执行加载全部tar包命令for img in *.tar; do echo 正在加载: $img; docker load -i $img; done第 4 步初始化集群kubeadm init \ --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \ --kubernetes-version v1.30.14 \ --pod-network-cidr 10.244.0.0/16 \ --apiserver-advertise-address10.0.1.107 # 实际服务器IP填写如果执行完初始化秒出现error执行以下命令临时开启 Linux 系统的 IPv4 数据包转发功能echo 1 /proc/sys/net/ipv4/ip_forward拉取网络插件后续kube-flannel.yml需要的镜像docker pull flannel/flannel:v0.26.7 docker pull flannel/flannel-cni-plugin:v1.6.2-flannel1第 5 步配置 kubectl 并安装 Flannel 网络1.配置 kubectl 访问权限mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config2.拉取kube-flannel.yml文件curl -o kube-flannel.yml https://mirror.ghproxy.com/https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml如果上边未成功更换以下链接curl -L -o kube-flannel.yml https://gh-proxy.com/https://github.com/flannel-io/flannel/releases/download/v0.26.7/kube-flannel.yml查看文件是否存在;ls -lh kube-flannel.yml拉取成功3.修改yml镜像内容sed -i s|docker.io/flannel/flannel|docker.m.daocloud.io/flannel/flannel|g kube-flannel.yml4.执行应用文件kubectl apply -f kube-flannel.yml5.等待 30 秒验证集群状态sleep 30 kubectl get nodes kubectl get pods -n kube-system6.这样得结果说明k8s部署成功