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

第8章. Helm 与Kustomize

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

Kubernetes对象可通过命令式kubectl命令创建、修改和删除,也可通过运行kubectl命令处理声明对象期望状态的配置文件(称为配置文件)实现。配置文件的主要定义语言是YAML ,但也可选择JSON格式——该格式在Kubernetes社区中的采用率较低。 建议开发团队将这些清单文件提交并推送到版本控制仓库,这有助于追踪和审计随时间推移的变更。

在Kubernetes中建模应用程序通常需要一组辅助对象,每个对象都可能拥有独立的清单。例如:您可能需要创建部署(Deployment)在五个Pod上运行应用程序,配置映射(ConfigMap)将配置数据注入为环境变量,以及服务(Service)用于暴露网络访问。

若仅通过单独的kubectl命令管理完整应用程序堆栈并不现实。此时便需要Helm和Kustomize等开源工具的介入。它们能让您便捷地将应用程序堆栈与集群组件的生命周期作为整体进行管理,同时支持在部署时根据上下文调整参数。

Helm操作实践

Helm是Kubernetes清单文件的包管理器( ),同时提供模板引擎。运行时,它会将YAML模板文件中的占位符替换为用户实际定义的值。Helm可执行文件生成的产物是图表文件(chart file),该文件以TAR格式打包应用程序API资源的构成清单( )。用户可将图表文件上传至图表仓库( )。 仓库 以便其他团队部署打包的清单。Helm 生态系统提供大量适用于常见场景的可复用图表可在Artifact Hub检索(例如运行Grafana或 PostgreSQL)。

鉴于 Helm 功能丰富,本文仅讨论基础内容。考试不要求您成为 Helm 专家,而是希望您熟悉使用 Helm 安装现有软件包的工作流程。构建和发布自定义图表超出考试范围。有关 Helm 的详细信息,请参阅文档。本文描述功能所使用的 Helm 版本为 3.19.0。

管理现有图表

作为开发者,您希望复用现有功能而非耗费精力自行定义配置。例如,您可能需要在集群中部署开源监控服务 Prometheus。

Prometheus需要安装多个Kubernetes基础组件。值得庆幸的是,Kubernetes社区提供了Helm图表,使其能够以Kubernetes操作员的形式轻松安装和配置所有动态组件。请重温第7章内容,回顾操作员模式的动态组件。

下列清单展示了Helm图表的典型使用与管理工作流。其中多数步骤需使用helm可执行文件 :

  1. 识别要安装的图表

  2. 添加包含图表的仓库

  3. 从存储库安装图表

  4. 验证图表安装的 Kubernetes 对象

  5. 渲染已安装图表列表

  6. 升级已安装的图表

  7. 若不再需要图表功能则卸载图表

后续章节将逐项说明这些步骤。

识别图表

多年来,Kubernetes 社区已实现并发布了数千个 Helm 图表。Artifact Hub 提供基于网页的搜索功能,支持通过关键词发现图表。

假设您需要查找安装持续集成解决方案Jenkins的图表,只需在搜索框输入"jenkins"并按下回车键。图8-1展示了ArtifactHub的搜索结果列表。

图8-1. 在Artifact Hub上搜索Jenkins 图表

截至撰写本文时,该关键词有141个匹配项。点击任意搜索结果即可查看图表详情,包括概述说明及图表文件所在仓库。此外,您还能查阅图表文件捆绑的模板,这些模板标明安装时将创建的对象及其配置选项。 ...

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