在 CentOS 上部署 Kubernetes(k8s) 时,报错原因很多,但大多数问题都集中在 系统环境、容器运行时、网络、镜像源、版本兼容性 等方面。下面我按 常见报错 → 排查思路 → 解决方案 给你一个实用指南。
cat /etc/centos-release
推荐:
setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable firewalld --now
swapoff -a
sed -i '/swap/d' /etc/fstab
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
failed to create containerd container
container runtime is not running
systemctl enable containerd --now
ctr -v
containerd config default > /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
systemctl restart containerd
kubeadm init error: unable to connect to the API server
journalctl -xeu kubelet
kubeadm config images list
| 原因 | 解决 |
|---|---|
| 镜像拉不下来 | 使用国内镜像 |
| 端口被占用 | 检查 6443 |
| kubelet 没启动 | systemctl restart kubelet |
kubeadm init \
--image-repository registry.aliyuncs.com/google_containers \
--pod-network-cidr=10.244.0.0/16
kubelet: failed to run Kubelet: misconfiguration
journalctl -u kubelet -f
systemctl restart containerd
systemctl restart kubelet
network plugin is not ready: cni config uninitialized
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
⚠️ 注意:
10.244.0.0/16kubectl get nodes
kubectl describe node <node>
ErrImagePull
docker pull registry.aliyuncs.com/google_containers/pause:3.9
或使用:
kubeadm config images pull \
--image-repository registry.aliyuncs.com/google_containers
✅ swapoff -a
✅ SELinux disabled
✅ firewalld stopped
✅ containerd running
✅ kubelet running
✅ CNI installed
✅ 6443 port listening
| 组件 | 版本 |
|---|---|
| CentOS | 7.9 |
| Kubernetes | 1.26 / 1.28 |
| containerd | 1.6.x |
| Flannel | latest |
你可以直接把 报错原文 发给我,例如:
kubeadm init 报错:
xxx
或者:
journalctl -u kubelet --no-pager | tail -n 50
我可以直接帮你 逐行分析 + 给出精确解决方案 ✅