Kick off your book project in 2 hours, get started with GhostAI in 2 hours, or do both! Free live workshops, on Zoom. You’ll leave with a real book project and a clear plan to keep going. Saturday, June 27, 2026.

Leanpub Header

Skip to main content

面向所有人的 Kubernetes

从零构建云原生数据中心

This book is 100% completeLast updated on 2026-05-30

大多数 Kubernetes 书籍教你 YAML。这本书教你构建一个数据中心。

你从 #!/usr/bin/env bash 开始。最终用一个命令就能配置、重载和拆除一个完整的多服务集群。没有魔法。没有黑盒。只有你、Bash,以及你亲手构建的云原生平台。

This book is a translation into Chinese (Simplified) of Kubernetes for All which was originally written in English

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
About

About

About the Book

开发者体验就是基础设施。每天都能交付的团队和害怕部署的团队之间的区别不在于天赋——而在于工具。快速反馈循环、不可变部署、自愈集群、可观测输出。这些都不是奢侈品。它们就是你在本书中要构建的东西。

大多数 Kubernetes 教程止步于 kubectl apply。你已经知道这些命令。你所缺少的是将这些命令粘合成一个开发平台的脚本——在 30 秒内配置集群、按照你期望的方式缓存镜像重建、在不丢失连接的情况下重载服务,并在出错时准确告诉你发生了什么。

这是一本关于云原生工程实践的书。不是幻灯片。不是白皮书。Bash、Docker、Helm 和 Kind——通过五个原则串联起来:基础设施即代码、不可变部署、快速反馈、大声失败并自愈、可观测。每一章都为其中之一服务。最后一章回应了它们:这些不是抽象的理想。它们就是你构建的东西。

你将构建什么

datacenter.sh ——一个配置并运行完整 Kubernetes 环境的单一脚本:16 个微服务、PostgreSQL、KRaft 模式下的 Kafka,以及一个 Web 前端。本地 Kind 集群或裸金属数据中心——相同的代码路径。你编写每一行。你拥有最终成果。

第一部分涵盖 Bash 基础,注重安全性和清晰性:set -o errexit 使脚本绝不会在损坏的状态下继续运行,生命周期钩子在退出时恢复终端状态,cron 模式仅在出错时转储完整日志。第二部分构建基础设施——在开始任何工作之前捕获缺失依赖的二进制验证、将密钥与脚本分离的配置管理、防止并发运行破坏集群状态的脚本锁定。第三部分涵盖 Kubernetes 操作:零停机滚动重启、使用参数数组的幂等 Helm 部署、就绪探针、以及尊重层缓存的 Docker 构建。第四部分贯穿完整的配置序列,从命名空间创建到确认一切正常运行的 curl /health,加上重载、恢复和清理。

每章结尾都有动手练习。附录包含标志参考、故障排除指南和术语表。

本书适合谁

你部署到 Kubernetes,你希望工具属于你自己——版本受控、可理解、快速。你能读懂 Bash。你想以生产质量编写它。你希望你的内部开发循环——修改代码、构建、部署、验证——只需几秒钟,而不是几分钟。

不需要认证。只需要 Docker、Kind,以及构建真实东西的渴望。

Share this book

This book is a translation into Chinese (Simplified) of Kubernetes for All which was originally written in English

Author

About the Author

Joel Bryan Juliano

Hi, I'm Joel.

I am Senior Software Engineer with 20+ years of experience.

And with over 20 years in the game, I’ve seen it all and loved every minute of it.

Originally from the Philippines, I am now a Dutchman living in Amsterdam together with my family.

My journey has taken me through a variety of industries, from sports streaming to cybersecurity, and everything in between.

Along the way, I’ve picked up a diverse set of skills and experiences, in which I document into books.

Translations

Translations

Contents

Table of Contents

引言:用 Bash 粘合 Kubernetes

  1. 先决条件
  2. 为什么选择 Bash?
  3. 我们要构建什么
  4. 入口点:setup.sh
  5. 启动 datacenter.sh
  6. 动手练习

安全设置、初始化和生命周期钩子

  1. 全局 Set 选项
  2. Shell 脚本检查工具:shellcheck
  3. 脚本初始化
  4. 主控制器
  5. 错误处理器
  6. 退出处理器
  7. 完整脚本
  8. 动手练习

退出码与受控退出

  1. script_exit 函数
  2. 退出码约定
  3. Bash 安全模式回顾
  4. 更新后的脚本
  5. 动手练习

Cron 模式与 IO 重定向

  1. Cron 模式做什么
  2. 文件描述符
  3. 为 Cron 模式重定向
  4. 更新错误处理器
  5. 更新退出处理器
  6. 在 main 中注册 cron_init
  7. 更新后的脚本
  8. 动手练习

库模式:组织 Bash 代码库

  1. lib/ 目录
  2. 在 main 中加载库
  3. 编写库文件
  4. 命名约定
  5. 依赖图
  6. 两个值得现在了解的实用库
  7. 动手练习

终端颜色与日志记录

  1. 日志库
  2. 颜色初始化
  3. log 函数
  4. verbose_print — 详细模式输出
  5. 更新 init
  6. 更新 main
  7. 更新错误处理器
  8. 动手练习

验证辅助函数与二进制检查

  1. lib/script.sh
  2. check_binary — 必需工具检测
  3. check_required_binaries — 系统前提条件
  4. is_kind — 模式检测
  5. check_arguments — 变量存在性验证
  6. check_directories — 路径验证
  7. check_files — 文件存在性验证
  8. check_repos — 仓库存在性守卫
  9. build_path — PATH 构建
  10. 在 init 链中使用辅助函数
  11. 动手练习

配置管理

  1. 配置文件
  2. lib/config.sh
  3. get_configurations — 交互式设置
  4. 在 main 中读取配置
  5. Docker 网络模式
  6. 动手练习

脚本锁定:防止并发运行

  1. 为什么是目录,而不是文件
  2. lock_init
  3. 过期锁处理
  4. 动手练习

完整的参数解析

  1. parse_params
  2. script_usage — 帮助文本
  3. 连接 parse_params 到 main
  4. 动手练习

本地模式与 Kind 集群管理

  1. 为什么是 Kind
  2. lib/kind.sh
  3. start_env — 创建 Kind 集群
  4. stop_env — 停止集群
  5. delete_env — 销毁集群
  6. 加载镜像到 Kind
  7. 无需 Docker 环境切换
  8. 动手练习

Docker 操作

  1. lib/docker.sh
  2. safe_docker — 基础包装器
  3. safe_docker_build — 构建镜像
  4. safe_docker_run — 运行容器
  5. 加载镜像到 Kind
  6. Docker Compose 操作
  7. docker_cleanup — 移除死容器和镜像
  8. 动手练习

使用 kubectl 管理 Kubernetes

  1. lib/kubectl.sh
  2. safe_kubectl — 基础包装器
  3. kubectl_install_resource_from_file
  4. kubectl_install_database — PostgreSQL 设置
  5. kubectl_restart — 滚动重启
  6. DNS 管理
  7. 重启所有 Deployment
  8. 动手练习

Helm:Kubernetes 的包管理器

  1. lib/helm.sh
  2. safe_helm — 基础包装器
  3. k8s/ 中的 Helm Charts
  4. helm_install_service — 通用服务安装器
  5. helm_install_core_service — 基于模板的服务
  6. 安装 Config Releases
  7. 更新函数 — 无需重新安装的升级
  8. Traefik — Ingress 控制器
  9. 动手练习

构建服务

  1. 构建管道
  2. lib/build.sh
  3. build_service — 核心构建函数
  4. 服务组函数
  5. build_images_init — 构建分派器
  6. lib/install_deps.sh
  7. check_registry
  8. 动手练习

从零开始配置

  1. 系统架构
  2. 完整配置序列
  3. 逐步说明
  4. Kubernetes 集群参数
  5. Kubernetes 清单参考
  6. 成功的样子
  7. 动手练习

重载与恢复操作

  1. lib/reload_services.sh
  2. reload_services — 轻量级服务刷新
  3. reload_services_init — 重载分派器
  4. lib/reload_kubernetes.sh
  5. reload_all_kubernetes — 完全集群重建
  6. 动手练习

拆除与清理

  1. 停止环境
  2. 删除环境
  3. 完全 Kubernetes 拆除
  4. Docker 清理
  5. 退出处理器:完整版本
  6. 整合完整脚本
  7. 完整的 main() 函数
  8. 完整的 init 函数
  9. 完整生命周期
  10. 你构建的开发者体验
  11. 动手练习

附录:datacenter.sh 命令参考

  1. setup.sh
  2. datacenter.sh
  3. 退出码
  4. 可链接 vs 不可链接参数
  5. 故障排除
  6. 常见工作流

术语表

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub