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

第18章 入口点

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

第十七章探讨了服务原语的目的与创建。当需要向外部消费者暴露应用程序时,选择合适的服务类型至关重要。最实用的选择通常是创建类型为负载均衡器的服务 。此类服务通过分配可供Kubernetes集群外部消费者访问的外部IP地址,提供负载均衡能力。

然而,为每个外部可访问的应用程序选择负载均衡器服务存在弊端。在Cloud服务提供商环境中,每个服务都会触发外部负载均衡器的配置,导致成本增加。此外,管理大量负载均衡器服务对象会带来管理挑战,因为每个外部可访问的微服务都需要建立新的对象。

为缓解这些问题,Ingress 原语应运而生,它为应用程序堆栈提供单一的负载均衡入口点。Ingress 能够根据可选的 DNS 可解析主机名和 URL 上下文路径,将外部 HTTP(S) 请求路由至集群内一个或多个服务。本章将指导您创建并访问 Ingress。

在 minikube 中访问 Ingress

在 minikube 中访问 Ingress 需要特殊处理。详细操作指南请参阅 Kubernetes 教程《使用 NGINX Ingress 控制器在 Minikube 上配置 Ingress》。

Ingress操作实践

Ingress通过外部可访问URL向集群外的客户端暴露HTTP(及可选的HTTPS)路由。通过Ingress配置的路由规则决定了流量应如何转发。 Cloud服务商的Kubernetes环境通常会部署外部负载均衡器 。Ingress从负载均衡器获取公共IP地址。如图18-1所示,可根据特定URL上下文路径配置规则,将流量路由至多个服务 。

Diagram illustrating how an Ingress routes HTTP(S) traffic from the external load balancer to specific services within a Kubernetes cluster based on URL paths.
图 18-1. 通过 HTTP(S)管理对服务的 外部访问

图18-1所示场景将Ingress实例化为域名next.example.com的HTTP(S)调用唯一入口点。根据提供的URL上下文,Ingress将流量导向两个虚拟服务:一个用于业务应用程序,另一个用于获取应用程序相关指标。

具体而言,URL上下文路径/app将被路由至负责管理业务应用程序的App服务;而向URL上下文/metrics发送请求时,调用将转发至能够返回相关指标的Metrics服务。

安装Ingress控制器

Ingress 要正常运作,Ingress 控制器不可或缺。该控制器评估由 Ingress 制定的规则集,从而决定流量路由。Ingress 控制器的选择通常取决于 Kubernetes 集群管理员的具体用例、需求和偏好。 值得关注的生产级Ingress控制器实例 包括F5 NGINX Ingress Controller或AKS应用网关Ingress控制器。更多选项可参阅Kubernetes官方文档

使用我们当前采用的NGINX Ingress控制器时,安装后应至少发现一个运行该控制器的Pod。以下输出展示了NGINX Ingress控制器在ingress-nginx命名空间中创建的Pod:

$ kubectl get pods -n ingress-nginx NAME READY STATUS ...
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