温馨提示×

centos k8s为何调度异常

小樊
34
2026-08-04 21:33:44
栏目: 智能运维

“CentOS 上 Kubernetes 调度异常”本身是一个比较宽泛的问题,调度异常可能来自 节点、Pod、调度器、资源、网络、系统组件 等多个层面。下面我按常见原因 → 排查思路 → 解决方案给你一个系统性的分析,基本能覆盖 90% 的 CentOS + k8s 场景。


一、先明确“调度异常”的表现

请先确认是哪一种:

  1. Pod 一直 Pending
  2. Pod 调度后启动失败
  3. Pod 被反复调度 / 驱逐
  4. 节点 NotReady,Pod 不调度
  5. 新建 Pod 不调度,但集群看起来正常

不同表现,根因完全不同。


二、最常见原因(CentOS 场景)

1️⃣ 节点资源不足(最常见)

表现

  • Pod Pending
  • kubectl describe pod 看到:
    Insufficient cpu
    Insufficient memory
    

原因

  • requests 设置过高
  • 节点实际资源被系统 / 其他组件占用
  • CentOS 默认 kubelet 会预留资源

排查

kubectl describe node <node>

重点看:

Allocatable
Non-terminated Pods

解决

  • 降低 Pod requests
  • 扩容节点
  • 调整 kubelet 预留(高级)

2️⃣ 节点 NotReady(CentOS 常见问题)

表现

kubectl get nodes

状态为 NotReady

常见原因

kubelet 没启动 / 崩溃

systemctl status kubelet
journalctl -u kubelet -f

容器运行时异常(docker / containerd)

systemctl status docker
systemctl status containerd

CentOS 防火墙 / SELinux

getenforce
systemctl status firewalld

时间不同步

timedatectl status
chronyc sources

解决

systemctl restart kubelet
systemctl restart docker

3️⃣ 调度器本身异常(kube-scheduler)

表现

  • 所有新 Pod 都 Pending
  • 老 Pod 不受影响

排查

kubectl get pods -n kube-system | grep scheduler
kubectl logs kube-scheduler-xxx -n kube-system

常见原因

  • scheduler 挂了
  • 和 apiserver 网络不通
  • 证书过期(CentOS 常见)

4️⃣ 污点(Taint)/ 容忍(Toleration)问题

表现

  • Master 节点不调度 Pod
  • 某些节点怎么都不调度

排查

kubectl describe node | grep Taint

常见:

node-role.kubernetes.io/master:NoSchedule

解决

  • 加 toleration
  • 或去掉 taint(不推荐生产)
kubectl taint nodes <node> node-role.kubernetes.io/master:NoSchedule-

5️⃣ 亲和性 / 反亲和性配置错误

表现

  • Pod 一直 Pending
  • 明明有节点却不用

排查

kubectl describe pod <pod>

看:

node selector
affinity

常见错误

  • nodeSelector 指定不存在的 label
  • requiredDuringSchedulingIgnoredDuringExecution 条件太严格

6️⃣ 磁盘 / Inode 问题(CentOS 特别常见)

表现

  • 节点 NotReady
  • Pod 被驱逐(Evicted)

排查

df -h
df -i

常见原因

  • /var/lib/docker/var/lib/kubelet
  • 日志没清理

解决

docker system prune -f
journalctl --vacuum-time=7d

7️⃣ 证书过期(CentOS 老集群高发)

表现

  • kubelet 无法连接 apiserver
  • 调度异常、节点 NotReady

排查

openssl x509 -in /etc/kubernetes/pki/apiserver.crt -noout -dates

解决

  • kubeadm 续期
kubeadm certs renew all
systemctl restart kubelet

三、快速定位“调度异常”的标准流程 ✅

Step 1:看 Pod 状态

kubectl describe pod <pod>

Step 2:看节点状态

kubectl get nodes
kubectl describe node <node>

Step 3:看调度器

kubectl logs -n kube-system kube-scheduler-xxx

Step 4:看系统层(CentOS 特有)

systemctl status kubelet
df -h
free -m

四、CentOS 比别的系统更容易踩的坑

问题 原因
SELinux 阻止 kubelet
firewalld 端口不通
内核版本低 调度 / 网络异常
yum 源问题 组件版本不一致
磁盘满 节点 NotReady

五、我可以进一步帮你精准定位

如果你愿意,可以直接贴以下信息(脱敏即可):

  1. kubectl get nodes
  2. kubectl describe pod <pod>
  3. kubectl describe node <node>
  4. k8s 版本 + CentOS 版本
  5. 容器运行时(docker / containerd)

我可以直接帮你判断是哪一层的调度问题,并给出对应的修复命令

0