温馨提示×

centos为啥部署不了k8s

小樊
41
2026-09-12 06:24:26
栏目: 智能运维

CentOS 上“部署不了 Kubernetes” 并不是一个单一原因,通常是环境、版本、配置或网络几类问题叠加。下面按常见原因给你系统梳理一下,基本能覆盖 90% 的情况。


一、CentOS 版本问题(最常见)

1️⃣ CentOS 8 已停止维护

  • CentOS 8:2021-12-31 已 EOL
  • 官方源、docker 源、k8s 源很多已失效
  • 表现:
    • yum install 报错
    • kubeadm 装不上
    • 镜像拉不下来

✅ 建议:

  • 使用 CentOS 7.9
  • 或迁移到:
    • Rocky Linux
    • AlmaLinux
    • Ubuntu 22.04(更推荐)

二、容器运行时没装对(K8s 1.24+ 重点)

2️⃣ Docker 不能直接用了(1.24 之后)

  • Kubernetes 1.24+ 移除了 dockershim
  • 必须:
    • containerd
    • 或 cri-o

❌ 错误做法:

yum install docker
kubeadm init

✅ 正确做法(containerd 示例):

yum install -y containerd
systemctl enable --now containerd

三、swap 没关(必踩坑)

Kubernetes 明确要求关闭 swap

❌ 现象:

[ERROR Swap]: running with swap on is not supported

✅ 解决:

swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab

四、防火墙 / SELinux / 端口问题

3️⃣ 防火墙没关或端口不通

K8s 需要大量端口(6443、10250 等)

✅ 快速排查:

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

五、网络问题(镜像拉不到)

4️⃣ k8s.gcr.io 被墙

国内环境直接 kubeadm init 必失败

❌ 报错:

failed to pull image k8s.gcr.io/kube-apiserver

✅ 解决方案:

  • 使用国内镜像:
kubeadm init \
--image-repository registry.aliyuncs.com/google_containers

或提前拉镜像:

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/...

六、系统参数没改(内核层面)

5️⃣ iptables / 桥接没开

K8s 要求:

modprobe br_netfilter
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables

否则:

  • Pod 不通
  • kubeadm 直接失败

七、CPU / 内存不足

6️⃣ 最低要求没达到

  • Master:≥ 2 CPU,≥ 2G 内存
  • Node:≥ 1 CPU

❌ 云服务器 1C1G 基本跑不起来


八、常见错误总结(速查)

问题 原因
kubeadm init 卡住 镜像拉不到
node NotReady 网络插件没装
swap 报错 没关 swap
docker 报错 1.24+ 不支持
yum 报错 CentOS 8 源失效

九、如果你愿意,我可以直接帮你

你可以贴一下:

  1. CentOS 版本(cat /etc/redhat-release
  2. K8s 版本
  3. 报错完整日志

我可以直接告诉你 是哪一步挂了、怎么改、甚至给你一份可跑的部署脚本

0