Skip to Content
《Kubernetes 最佳实践》第二版
book

《Kubernetes 最佳实践》第二版

by Brendan Burns, Eddie Villalba, Dave Strebel, Lachlan Evenson
May 2025
Intermediate to advanced
324 pages
3h 31m
Chinese
O'Reilly Media, Inc.
Content preview from 《Kubernetes 最佳实践》第二版

第 8 章 资源管理 资源管理

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

在本章中,我们将重点介绍管理和优化 Kubernetes 资源的最佳实践。我们将讨论工作负载调度、集群管理、pod 资源管理、命名空间管理和扩展应用。我们还深入探讨了 Kubernetes 通过亲和、反亲和、污点、容忍和节点选择器提供的一些高级调度技术。

我们将向您展示如何实施资源限制、资源请求、pod 服务质量、PodDisruptionBudgets、LimitRangers 和反亲和性策略。

Kubernetes 调度器

Kubernetes 调度器是控制平面中托管的主要组件之一。调度器允许 Kubernetes 为部署到集群中的 pod 做出放置决策。它根据集群的约束条件和用户指定的约束条件对资源进行优化。它使用基于谓词和优先级的评分算法。

谓词

Kubernetes 用来做出调度决定的第一个函数是谓词函数,它决定了 pod 可以调度到哪些节点上。 这意味着一个硬约束,因此它会返回 true 或 false 值。例如,当 pod 要求 4 GB 内存,而某个节点无法满足这一要求时。该节点将返回 false 值,并从 pod 可调度的可行节点中删除。另一个例子是,如果节点被设置为不可调度,那么它就会从调度决策中移除。

调度程序根据限制性和复杂性的顺序检查谓词。截至本文撰写时,调度程序会检查以下谓词:

    CheckNodeConditionPred,
    CheckNodeUnschedulablePred,
    GeneralPred,
    HostNamePred,
    PodFitsHostPortsPred,
    MatchNodeSelectorPred,
    PodFitsResourcesPred,
    NoDiskConflictPred,
    PodToleratesNodeTaintsPred,
    PodToleratesNodeNoExecuteTaintsPred,
    CheckNodeLabelPresencePred,
    CheckServiceAffinityPred,
    MaxEBSVolumeCountPred,
    MaxGCEPDVolumeCountPred,
    MaxCSIVolumeCountPred,
    MaxAzureDiskVolumeCountPred,
    MaxCinderVolumeCountPred,
    CheckVolumeBindingPred,
    NoVolumeZoneConflictPred,
    CheckNodeMemoryPressurePred,
    CheckNodePIDPressurePred,
    CheckNodeDiskPressurePred,
    MatchInterPodAffinityPred

优先事项

谓词表示一个真值或假值,并将一个节点排除在调度之外,而优先级值则根据一个相对值对所有有效节点进行排序。节点的优先级评分如下:

    EqualPriority
    MostRequestedPriority
    RequestedToCapacityRatioPriority
    SelectorSpreadPriority
    ServiceSpreadingPriority
    InterPodAffinityPriority
    LeastRequestedPriority
    BalancedResourceAllocation ...
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 实现云原生 DevOps(第二版)》

《使用 Kubernetes 实现云原生 DevOps(第二版)》

Justin Domingus, John Arundel
生产 Kubernetes

生产 Kubernetes

Josh Rosso, Rich Lander, Alex Brand, John Harris

Publisher Resources

ISBN: 9798341657250