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

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

by Justin Domingus, John Arundel
May 2025
Intermediate to advanced
356 pages
3h 47m
Chinese
O'Reilly Media, Inc.
Content preview from 《使用 Kubernetes 实现云原生 DevOps(第二版)》

第 2 章 使用 Kubernetes 的第一步 使用 Kubernetes 的第一步

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

你已经迈出了迈向更广阔世界的第一步。

欧比旺-克诺比,《星球大战:新希望

说完理论,让我们开始使用 Kubernetes 和容器。在本章中,你将构建一个简单的容器化应用程序,并将其部署到在你的机器上运行的本地 Kubernetes 集群。在这个过程中,你会遇到一些非常重要的云原生技术和概念:Docker、Git、Go、容器注册表和kubectl 工具。

提示

本章是互动式的!在本书中,我们会要求你在自己的计算机上安装软件、输入命令并运行容器,从而跟随示例进行学习。我们发现,这种学习方式比单纯的文字说明更有效。你可以在GitHub 上找到所有示例。

运行第一个集装箱

正如我们在第 1 章中看到的,容器是云原生开发的关键概念之一。构建和运行容器最常用的工具是 Docker。还有其他一些运行容器的工具,但我们将在后面详细介绍。

在本节中,我们将使用 Docker Desktop 工具构建一个简单的演示应用程序,在本地运行,并将镜像推送到容器注册中心。

如果你对容器已经非常熟悉,请直接跳到"你好,Kubernetes",真正的乐趣就从这里开始。如果你想知道容器是什么、如何工作,并在开始学习 Kubernetes 之前获得一些实际经验,请继续阅读。

安装 Docker 桌面

Docker Desktop 是一款适用于 Mac 和 Windows 的免费软件包。它自带一个完整的 Kubernetes 开发环境,你可以用它在笔记本电脑或台式机上测试你的应用程序。

现在就让我们安装 Docker Desktop,并用它来运行一个简单的容器化应用程序。如果你已经安装了 Docker,请跳过本节,直接进入"运行容器映像"。

下载适合你的电脑的Docker Desktop Community Edition版本,然后按照你的平台的说明安装 Docker 并启动它。

备注

Docker Desktop 目前不适用于 Linux,因此 Linux 用户需要安装Docker Engine,然后再安装Minikube(请参阅"Minikube")

完成上述操作后,您就可以打开终端并运行以下命令:

docker version
 ...
 Version:           20.10.7
 ...

具体输出结果会因平台而异,但如果 Docker 已正确安装并运行,则会看到类似所示的示例输出结果。

在 Linux 系统上,你可能需要运行sudo docker version 来代替。你可以用sudo usermod -aG docker $USER && newgrp docker 将自己的账户添加到 Docker 组,这样就不需要每次都用sudo 了。

什么是 Docker?

Docker实际上是几种不同但相关的东西:一种容器镜像格式、一种管理容器生命周期的容器运行库、一种用于打包和运行容器的命令行工具,以及一种用于容器管理的 API。我们在这里不必关心这些细节,因为 Kubernetes 支持的 Docker 容器是众多组件中的一个,尽管是重要的一个。

运行容器映像

究竟什么是容器镜像?技术细节对我们来说并不重要,但你可以把映像想象成一个 ZIP 文件。它是一个具有唯一 ID 的二进制文件,包含运行容器所需的一切。

无论你是直接使用 Docker 运行容器,还是在 Kubernetes ...

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 上管理云原生数据

在 Kubernetes 上管理云原生数据

Jeff Carpenter, Patrick McFadin
《Kubernetes 最佳实践》第二版

《Kubernetes 最佳实践》第二版

Brendan Burns, Eddie Villalba, Dave Strebel, Lachlan Evenson
生产 Kubernetes

生产 Kubernetes

Josh Rosso, Rich Lander, Alex Brand, John Harris
Cloud Native DevOps mit Kubernetes

Cloud Native DevOps mit Kubernetes

John Arundel, Justin Domingus

Publisher Resources

ISBN: 9798341659179