K8s Ingress 选型:Nginx / Traefik / APISIX / Istio Gateway
K8s 流量入口选 Ingress Controller 是搭集群必经的题。本文对比 4 个主流选项。
一句话
- Nginx Ingress:稳,文档全,默认选项
- Traefik:现代,配置友好,中小规模
- APISIX:性能强,插件多,国产
- Istio Gateway:要 service mesh 就选
对比
| 维度 | Nginx | Traefik | APISIX | Istio |
|---|---|---|---|---|
| 性能 | 高 | 中 | 最高 | 中 |
| 配置易用 | 中(annotation 多) | 高 | 中 | 低 |
| 插件 | 少 | 中 | 多 | 极多 |
| WebSocket / gRPC | 支持 | 支持 | 支持 | 支持 |
| 动态配置 | 需 reload | 是 | 是 | 是 |
| 社区 | 大 | 大 | 中 | 大 |
| 学习曲线 | 缓 | 缓 | 中 | 陡 |
Nginx Ingress:默认选
helm install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace \
--set controller.replicaCount=3 \
--set controller.resources.requests.cpu=200m \
--set controller.resources.requests.memory=256Mi
优点:
- 最广泛使用,遇到问题 Google 都有答案
- annotations 几乎覆盖 nginx.conf 所有指令
- 生产稳定性最佳
缺点:
- 改 backend 要 reload nginx(短暂中断)
- annotations 写多了乱
适合:中大规模、保守业务。
Traefik:现代友好
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: api
spec:
routes:
- match: Host(`api.example.com`)
kind: Rule
services:
- name: api
port: 8080
middlewares:
- name: rate-limit
优点:
- 配置语法清晰(IngressRoute CRD)
- 自动发现 Docker / K8s 服务
- 自带 Let's Encrypt 证书签发
缺点:
- 性能比 Nginx 略低
- 生产场景没 Nginx 久经考验
适合:小到中规模、新项目。
APISIX:性能党
基于 OpenResty (Nginx + Lua),性能极致。
helm install apisix apisix/apisix \
--namespace apisix --create-namespace \
--set gateway.type=LoadBalancer
优点:
- 性能最高(QPS 比 Nginx Ingress 高 30%+)
- 插件市场丰富(限流、鉴权、灰度、AB 测试)
- 全动态配置,零 reload
- Dashboard UI 友好
缺点:
- 国内文档好、国外社区相对小
- 故障排查需要懂一些 Lua
适合:高 QPS、网关有复杂逻辑(流量染色、灰度发布)。
Istio Gateway:上 mesh 就用
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: api-gw
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- "*.example.com"
只在你已经/准备用 Istio service mesh 时才考虑,单纯做入口太重。
选型决策树
要 service mesh?
└ Yes → Istio Gateway
└ No → 业务规模?
└ 小 → Traefik
└ 中大 → 网关有复杂逻辑(限流/鉴权/灰度)?
└ Yes → APISIX
└ No → Nginx Ingress
教训:选 Ingress Controller 主要看团队熟悉度——你能 5 分钟定位故障的那个,就是最好的。