Skip to Content
Kubernetes 认证管理员 (CKA) 学习指南 (Chinese Edition), 2nd Edition
book

Kubernetes 认证管理员 (CKA) 学习指南 (Chinese Edition), 2nd Edition

by Benjamin Muschko
January 2026
Intermediate to advanced
392 pages
4h 44m
Chinese
O'Reilly Media, Inc.
Content preview from Kubernetes 认证管理员 (CKA) 学习指南 (Chinese Edition), 2nd Edition

第14章·Pod 调度

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

调度器是集群组件 ,负责决定为运行Pod选择哪个节点 。本章将介绍通用调度算法以及Kubernetes概念,这些概念可用于表达软性与硬性要求以影响调度决策。

Pod调度算法

终端用户创建的Pod初始状态下未分配节点,此任务由调度器集群组件承担。调度器通过调度循环机制实时监测待调度Pod,评估可用节点后为Pod选择最适配的运行节点。

匹配节点遵循两步流程:筛选与评分。筛选步骤( )确定可运行 Pod 的节点列表(例如检查可用硬件容量)。评分步骤( )对剩余节点排序,选出最适合承载工作负载的节点。调度决策涵盖资源需求、亲和性与反亲和性配置等要素。Pod 调度算法可视化示意见图 14-1

Diagram illustrating the Pod scheduling algorithm, showing the flow from filtering nodes to scoring and selecting the most suitable node for running a workload.
图14-1. 容器 调度算法

Pod及其容器可定义资源需求以辅助节点选择。若所有节点均无法满足需求,则Pod保持未调度状态直至调度器再次检查;否则调度器将选择得分最高的节点并分配Pod。

搭建多节点开发集群

调度要求的实际效果通过多节点集群演示最为直观 。本章后续内容将采用包含一个控制平面节点和三个工作节点的集群架构,如图所示:

$ kubectl get nodes
NAME             STATUS   ROLES           AGE     VERSION
multi-node       Ready    control-plane   2m33s   v1.32.2
multi-node-m02   Ready    <none>          2m22s   v1.32.2
multi-node-m03   Ready    <none>          2m15s   v1.32.2
multi-node-m04   Ready    <none>          2m9s    v1.32.2

在Kubernetes环境中搭建多节点集群相当简单。多数开发集群实现( minikube和kind) 均支持创建多节点集群。以下命令使用minikube创建名为multi-node的前缀的四节点集群:

$ minikube start --kubernetes-version=v1.32.2 --nodes=4 -p multi-node

有关适用配置选项的详细信息,请参阅您所选Kubernetes开发集群的文档。

确定Pod运行的节点

调度Pod的前提是调度器正常运行 。调度器进程运行在控制平面节点的Pod中。可通过以下命令查找调度器Pod,请确保该Pod处于Running状态

$ kubectl get pods -n kube-system
NAME                        READY   STATUS    RESTARTS   AGE
kube-scheduler-multi-node   1/1     Running   0          5m10s

可通过kubectl getkubectl describe命令查询 Pod 运行节点。以下命令展示了针对名为nginx 的 Pod 的多种用法:

$ kubectl get pod nginx -o=wide NAME READY STATUS RESTARTS AGE IP NODE ... nginx 1/1 Running 0 3m49s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Kubernetes 上的生成式人工智能 (Chinese Edition)

Kubernetes 上的生成式人工智能 (Chinese Edition)

Roland Huß, Daniele Zonca
游戏化头脑风暴

游戏化头脑风暴

Dave Gray, Sunni Brown, James Macanufo

Publisher Resources

ISBN: 0642572314712