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

第16章. 持久

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

持久卷是卷概念中的一类特殊( ),其特性在于能够在Pod生命周期之外持续保存数据。持久卷的运作机制稍显复杂:持久卷作为实际将数据持久化存储至底层物理存储的资源实体。

持久卷声明 则代表连接Pod与持久卷的桥梁资源,负责向存储系统发起请求。

最后,Pod需要申领持久卷并将其挂载到内部容器可访问的目录路径。

图16-1展示了Pod、持久卷声明与持久卷之间的关系。

Diagram showing the relationship between a Pod, container, persistent volume claim, and persistent volume, illustrating the process of a Pod claiming a persistent volume.
图16-1. 从Pod申领 持久卷

持久卷操作

存储在卷上的数据在容器重启后仍可保留。在许多应用中,数据的生命周期远超应用程序、容器、Pod、节点乃至集群本身的存续时间。 数据持久化 确保数据生命周期与集群资源生命周期解耦。典型示例是数据库持久化的数据,这正是持久化卷的职责所在。Kubernetes通过两种基础组件实现数据持久化:PersistentVolume(持久化卷)和PersistentVolumeClaim(持久化卷声明)。

PersistentVolume是 中表示存储空间的基本单元,它与Pod完全解耦,因此拥有独立的生命周期。该对象捕获存储源(例如Cloud服务商提供的存储资源)。PersistentVolume可由Kubernetes管理员提供,也可通过映射存储类实现动态分配。

PersistentVolumeClaim用于请求PersistentVolume的资源 ——例如存储容量和访问类型。在Pod中,需使用persistentVolumeClaim类型通过PersistentVolumeClaim挂载抽象化的PersistentVolume。

卷类型

Kubernetes支持多种持久卷类型( ),以适配不同存储后端和使用场景。每种类型具有独特特性,适用于特定场景。表16-1列出了当前未废弃的最常用持久卷类型。

表 16-1. 持久 卷类型
输入命令 描述

hostPath

将主机节点的文件系统中的文件或目录挂载到 Pod 中。适用于开发和测试环境,但不推荐用于生产环境的多节点集群,因为它将 Pod 绑定到特定节点。

local

表示挂载的本地存储设备,如磁盘、分区或目录。性能优于远程存储,但需配置节点亲和性以确保Pod调度至正确节点。

nfs

允许多个Pod共享同一网络文件系统(NFS)挂载点。支持ReadWriteMany访问模式,适用于跨节点Pod间数据共享。

csi

容器存储接口(CSI)驱动程序,为容器化工作负载提供标准化存储系统暴露方案。多数现代存储解决方案均采用CSI驱动程序。

fc

光纤通道(FC)卷,支持将现有FC存储设备挂载至Pod。需节点配备FC硬件并完成相应配置。

iscsi

互联网小型计算机系统接口(iSCSI)卷,支持将现有iSCSI存储挂载至Pod。通过IP网络提供块级存储服务。

卷类型的选择取决于基础设施、性能需求以及是否需要跨多个Pod或节点共享存储。在云环境中,云服务商通常提供CSI驱动程序(如AWS EBS CSI驱动程序、GCE持久磁盘CSI驱动程序或Azure磁盘CSI驱动程序)以集成其原生存储服务。 ...

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