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

第13章 资源 需求、限制与配额

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

在Pod中执行的工作负载将消耗一定量的资源(如CPU和内存)。您应为这些应用程序定义资源需求。在容器层面,您可以定义运行应用程序所需的最小资源量,以及应用程序允许消耗的最大资源量。应用程序开发人员应通过负载测试或在运行时监控资源消耗来确定合适的资源配置。

Kubernetes 中的资源单位

Kubernetes 以毫核(m)单位(亦称毫CPU)衡量CPU资源,内存资源则以字节为单位。因此您可能看到资源定义为600 m或100 Mi。若需深入了解这些资源单位,建议查阅官方文档 中的"Kubernetes资源单位"章节。

Kubernetes管理员可实施措施来强制使用可用资源容量。本章将探讨该领域中的两个Kubernetes基础组件:ResourceQuota与LimitRange。ResourceQuota( )在命名空间层级定义聚合资源约束。LimitRange( )则作为策略,用于约束或默认分配特定类型单个对象(如Pod或PersistentVolumeClaim)的资源。

资源需求管理

建议为每个容器明确指定资源请求 和限制。确定资源需求并非易事,尤其对于尚未在生产环境中运行的应用程序。在开发周期早期进行负载测试有助于分析资源需求。部署至集群后,可通过监控应用程序的资源消耗进行进一步调整。

服务质量(QoS)类 在Kubernetes中, 会根据Pod的资源请求和限制自动将其划分为Guaranteed(保证级)、Burstable(突发级)或BestEffort(尽力级),从而确定节点资源紧张时的驱逐优先级。虽然理解QoS对生产工作负载至关重要,但CKA考试并未明确涵盖此内容,其更侧重于实际资源管理和Pod调度,而非底层驱逐优先级机制。

定义容器资源请求

在工作负载调度过程中, 这一指标会根据 Pod 中容器定义的资源请求进行作用( )。可指定的常用资源包括 CPU 和内存。调度器会确保节点资源容量能够满足 Pod 的资源需求。更具体地说,调度器会计算 Pod 中所有容器按资源类型划分的资源请求总和,并与节点可用资源进行对比。

Pod 中的每个容器均可定义独立的资源请求。表 13-1列出了可用选项及示例值。

表 13-1. 资源请求选项
YAML属性 描述 示例值

spec.containers[].resources.requests.cpu

CPU 资源类型

500m(五百毫秒CPU)

spec.containers[].resources.requests.memory

内存资源类型

64Mi(2^26 字节)

spec.containers[].resources.requests.hugepages-<size>

巨页资源类型

hugepages-2Mi: 60Mi

spec.containers[].resources.requests.ephemeral-storage

临时存储资源类型

4Gi

为阐明资源请求的用途,我们通过示例定义进行说明。示例13-1中的Pod YAML清单定义了两个容器,各自拥有独立的资源请求。任何允许运行该Pod的节点都需支持至少320 Mi内存容量和1250 m CPU资源,这是两个容器资源需求的总和。

示例 ...
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