CentOS 上部署 Kubernetes(K8s)报错是很常见的事情,原因通常集中在系统环境、容器运行时、网络、SELinux/防火墙、版本兼容性等方面。
我给你一个通用排查思路 + 常见错误速查表,基本能覆盖 90% 的坑。
cat /etc/centos-release
✅ 推荐:
⚠️ CentOS 8 已 EOL,建议换源或用 Stream。
uname -r
lsmod | grep br_netfilter
必须开启:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
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
systemctl disable firewalld --now
setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
swapoff -a
sed -i '/swap/d' /etc/fstab
kubeadm init 卡住或失败[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed
✅ 解决:
journalctl -xeu kubelet
systemctl status kubelet
常见原因:
failed to create kubelet: misconfiguration: kubelet cgroup driver: "systemd" is different from docker/containerd "cgroupfs"
✅ 解决(containerd 示例):
containerd config default > /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
systemctl restart containerd
kubelet 也要一致:
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"
failed to pull image k8s.gcr.io/kube-apiserver
✅ 解决(国内必备):
kubeadm init \
--image-repository registry.aliyuncs.com/google_containers \
--pod-network-cidr=10.244.0.0/16
kubectl get nodes
✅ 排查:
kubectl describe node <node>
journalctl -u kubelet
常见原因:
✅ 解决(Flannel 示例):
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
Port 10250 is in use
✅ 解决:
ss -lntp | grep 10250
✅ CentOS 7 + containerd + kubeadm
K8s 1.24 / 1.26 / 1.28
containerd 1.6.x
| 检查项 | 命令 |
|---|---|
| swap | free -m |
| SELinux | getenforce |
| 防火墙 | systemctl status firewalld |
| kubelet | systemctl status kubelet |
| 容器运行时 | systemctl status containerd |
| 网络插件 | kubectl get pods -A |
你可以直接把 完整报错信息 发我,比如:
kubeadm init 报错kubectl get nodes 显示 NotReady我可以按行帮你分析,甚至给你一份一键部署脚本(CentOS 专用)。