CentOS版本需与Kubernetes版本严格匹配,避免因版本不兼容导致部署失败:
部分旧内核版本(如3.x)的cgroup kmem account特性存在内存泄露问题,会导致节点无法分配内存。解决方案:
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf),添加--feature-gates=KubeletPodResourcesGetAllocatable=false参数,然后重启kubelet服务。Docker版本需符合Kubernetes的要求(如Kubernetes 1.26.x需搭配Docker 20.10.x),避免因版本冲突导致容器无法启动:
sudo yum remove -y docker-ce docker-ce-cli containerd.io彻底卸载。yum-utils工具安装兼容的Docker版本(如sudo yum install -y yum-utils && sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && sudo yum install -y docker-ce-20.10.17 docker-ce-cli-20.10.17 containerd.io)。/etc/docker/daemon.json),添加"exec-opts": ["native.cgroupdriver=systemd"],并重启Docker服务。Kubernetes对系统环境有特定要求,未正确配置会导致部署失败:
sudo setenforce 0临时关闭,修改/etc/selinux/config文件将SELINUX=enforcing改为SELINUX=disabled永久生效。sudo systemctl stop firewalld && sudo systemctl disable firewalld停止并禁用防火墙,或开放必要端口(如6443、10250-10252)。sudo swapoff -a临时关闭,修改/etc/fstab文件注释掉swap行永久生效(Kubernetes要求节点禁用swap)。ntp或chrony工具,确保所有节点时间同步(如sudo yum install -y chrony && sudo systemctl enable chronyd && sudo systemctl start chronyd)。Master节点与Worker节点的Kubernetes组件(kubelet、kube-proxy、kube-controller-manager等)版本需完全一致,避免因版本不匹配导致集群异常:
kubeadm安装时,通过--kubernetes-version参数指定版本(如sudo kubeadm init --kubernetes-version=v1.26.0)。kubeadm upgrade命令统一升级所有节点(如sudo kubeadm upgrade apply v1.26.1)。网络插件(如Flannel、Calico)需与Kubernetes版本兼容,且配置正确,否则会导致Pod无法通信:
sudo sysctl net.bridge.bridge-nf-call-iptables=1)。kubectl apply命令部署网络插件(如Flannel:kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml)。若仍遇到兼容性问题,可通过日志排查具体原因:
sudo journalctl -u kubelet -f实时查看kubelet运行日志。kubectl get pods --all-namespaces查看Pod是否处于Running状态,若有异常Pod,执行kubectl describe pod <pod-name>查看详细信息。kubeadm init输出的日志,或通过journalctl -u kube-apiserver查看API Server日志。