跳转至

资源、调度与驱逐

Scheduler 只为尚未绑定节点的 Pod 选择 Node;选定后由 kubelet 运行。调度是否成功取决于 requests、节点可分配资源、污点/容忍、亲和性、拓扑、PVC 和调度策略。

Requests 与 Limits

resources:
  requests:
    cpu: 200m
    memory: 512Mi
  limits:
    cpu: "1"
    memory: 1Gi
配置 调度/运行影响
CPU request Scheduler 预留的 CPU 依据,也影响 CPU 竞争权重
CPU limit 超过后通常被节流,不直接 OOM
Memory request Scheduler 计算节点容量的依据
Memory limit 超过后容器可能被 OOMKilled

不设置 request 会导致调度器无法反映真实需求;request 过大造成 Pending 和资源浪费,过小造成节点超卖、驱逐和性能抖动。

kubectl top nodes
kubectl top pods -A --containers
kubectl describe node <node>
kubectl describe pod <pod> -n <namespace>

QoS Class

等级 条件 节点内存压力时
Guaranteed 每个容器 CPU/内存 request 等于 limit 相对更晚被驱逐
Burstable 至少设置部分 request/limit,但不满足 Guaranteed 按使用与请求关系参与驱逐
BestEffort 没有设置 CPU/内存 request/limit 最先受影响

QoS 不是性能保证书,仍需容量规划、监控和业务限流。

NodeSelector 与亲和性

nodeSelector:
  workload: application
kubectl label node worker-01 workload=application
kubectl get nodes --show-labels

Node Affinity 支持更复杂的 required/preferred 规则;Pod Anti-Affinity 或 Topology Spread 可把副本分散到不同节点/可用区,避免全部副本落在同一故障域。

Taint 与 Toleration

Taint 让 Node 拒绝不匹配的 Pod;Toleration 只代表“允许调度”,不保证一定调度到该节点。

kubectl taint nodes gpu-01 dedicated=gpu:NoSchedule
tolerations:
  - key: dedicated
    operator: Equal
    value: gpu
    effect: NoSchedule

控制平面、GPU、存储或专用业务节点常用 Taint 隔离,配合 Node Affinity 指定目标。

Pod Pending 排查

kubectl describe pod <pod> -n <namespace>
kubectl get events -n <namespace> --sort-by=.lastTimestamp
kubectl get nodes
kubectl get pvc -n <namespace>

常见原因:Insufficient CPU/Memory、节点污点不匹配、亲和性无可用节点、PVC 未绑定、节点 NotReady、HostPort 冲突或 ResourceQuota 超限。

节点压力与驱逐

kubelet 在内存、磁盘、PID 等资源紧张时可能驱逐 Pod。DiskPressureMemoryPressurePIDPressureReady 可在 Node Condition 中查看。

kubectl get nodes
kubectl describe node <node>
kubectl get pods -A --field-selector spec.nodeName=<node>

OOMKilled 通常是容器超过 memory limit;Evicted 则常是节点整体压力。两者处理方向不同。

Priority 与 Preemption

PriorityClass 可让更高优先级 Pod 在资源不足时抢占低优先级 Pod。它只应用于真正关键工作负载;滥用高优先级会让普通业务无法调度,并不能增加集群容量。

官方参考:Scheduling, Preemption and EvictionResource Management