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

第6章 认证 、授权 与准入控制

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

API服务器 是通往Kubernetes集群的网关。任何人类用户、客户端(如kubectl)、集群组件或服务账户均需通过HTTPS向 发起RESTful API调用以访问API服务器。该服务器是执行创建Pod或删除Service等操作的核心枢纽

本章将重点探讨与 API 服务器相关的安全特性。有关 API 服务器内部机制及 Kubernetes API 使用方法的详细说明,请参阅 《Kubernetes管理指南》 (布伦丹·伯恩斯与克雷格·特雷西著,O'Reilly出版社,2018年)。

处理API请求

图6-1展示了调用API服务器时请求经历的各个阶段。更多参考信息可查阅Kubernetes官方文档

请求处理的第一阶段是身份验证。身份验证 通过检查客户端证书或承载令牌来验证调用者的身份。若承载令牌 关联服务账户,则在此阶段进行验证。

Diagram showing the stages of API server request processing: authentication, authorization, admission control, and process.
图6-1. API服务器请求 处理流程

第二阶段判断第一阶段验证的身份是否具备访问请求动词及HTTP路径的权限。因此第二阶段处理请求授权 ,采用标准Kubernetes RBAC模型 实现。此处需确保服务账户被允许列出Pod,或在请求创建新服务对象时具备相应权限。

请求处理的第三阶段涉及准入控制。准入控制 在请求处理前验证其格式是否正确或是否需要修改。例如,准入控制策略可确保创建Pod的请求包含特定标签的定义,若请求未定义该标签则予以拒绝。

通过kubectl进行身份验证

开发者通过运行kubectl命令行工具与Kubernetes API交互。每次执行kubectl命令时,底层对API服务器的HTTPS调用都需要进行身份验证 。

Kubeconfig

kubectl使用的凭证存储在$HOME/.kube/config文件中, 即kubeconfig配置文件。该文件 定义了需交互集群的API服务器端点,以及集群注册用户列表(含客户端证书形式的凭证)。 特定命名空间 中集群与用户的映射关系称为上下文kubectl通过当前选定的上下文确定通信对象集群及应使用的凭证。

合并多个kubeconfig文件

可将环境变量KUBECONFIG指向一组 kubeconfig 文件( )。运行时,kubectl会合并这些定义的 kubeconfig 文件内容并使用。默认情况下KUBECONFIG未设置,将回退至$HOME/.kube/config

示例 6-1展示了一个 kubeconfig 文件。请注意,示例中指定的文件路径是用户特定的,在您的环境中可能有所不同。您可以在config 资源类型的API 文档中找到所有可配置属性的详细说明。

示例 6-1. kubeconfig文件示例
apiVersion: v1
kind: Config
clusters:                   1
- cluster ...
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