Ingress
一句话解释
Ingress 是 Kubernetes resource 那个 routes 外部 HTTP/HTTPS traffic 到 Services based on host and path 规则.
用大白话说
An Ingress is Kubernetes' way of exposing your application to the outside world using HTTP/HTTPS. Instead of exposing each Service individually, you define an Ingress with routing rules — e.g., "发送 traffic 到 /API 到 API service, and 一切 else 到 frontend service."
An Ingress can also handle TLS termination (HTTPS), host-based routing (e.g., api.example.com vs www.example.com), and path-based routing. To actually process Ingress rules, you need an Ingress Controller — a pod that runs a reverse proxy like nginx or traefik.
Ingress is more efficient than using multiple LoadBalancer Services because you only need one load balancer (the Ingress Controller) to route to many Services.
示例
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /api
backend:
service:
name: api-service
port:
number: 80
- path: /
backend:
service:
name: web-service
port:
number: 80这个 Ingress routes /API 到 API-service and 一切 else 到 web-service for host 示例.com.
工作原理
- You define an Ingress with routing rules (host, path, backend Service).
- An Ingress Controller (e.g., nginx-ingress) watches for Ingress resources.
- The controller configures its reverse proxy to route traffic accordingly.
- External traffic hits the Ingress Controller, which routes it to the right Service.
常见混淆
容易混淆的对象: Service
关键区别: Service routes traffic 在内 cluster; Ingress routes 外部 HTTP/HTTPS traffic based on host and path 规则.
相关术语
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。