--- source_url: "https://mp.weixin.qq.com/s/t1lZeXhRCbZ-3JJXP30w6g" tags: [wechat, article, claude, openai, gpt, agent, harness, openclaw] ingested: 2026-05-23 sha256: "" --- # 告别 Ingress Nginx:云原生 API 网关 Gateway API 使用指引 **来源:** 阿里云云原生 | 如漫 | 2026年5月23日 ## 核心要点 ### Ingress 的局限性 - **表达能力不足**:仅支持基础域名和路径路由,高级策略依赖自定义 annotation,不标准且不可移植 - **缺乏角色分层**:所有配置塞在一个资源里,权责不清 - **扩展性差**:annotation 五花八门,不同 Ingress 控制器之间互不兼容 ### Gateway API 三层资源模型 | 资源 | 职责 | 负责角色 | |------|------|---------| | GatewayClass | 定义网关实现类型 | 平台管理员 | | Gateway | 声明网关实例、监听端口和域名 | 集群运维 | | HTTPRoute | 定义具体路由规则、流量策略 | 应用开发者 | ### 原生支持的能力(无需自定义注解) - 精确路由匹配(路径/域名/请求头/查询参数/HTTP方法) - 请求/响应修改(内置 Filter 机制) - 流量切分(权重分发,灰度发布) - 请求重定向与 URL 重写 - 跨命名空间路由 + ReferenceGrant 安全保证 - **Gateway API Inference Extension(GIE)**:推理场景智能路由,感知请求队列深度/KV Cache 命中率 ### 阿里云云原生 API 网关优势 1. **双模并行**:Ingress 和 Gateway API 共存,平滑过渡 2. **完善迁移工具**:兼容主流 Nginx Ingress 注解,灰度切流 + 一键回滚 3. **控制台可视化 + kubectl 声明式管理** 4. **基于 Higress 开源生态** ### 实战步骤 1. 开启 Gateway API 监听(控制台导入 Gateway API) 2. 部署示例应用(httpbin) 3. 创建 GatewayClass → Gateway → HTTPRoute YAML 4. 验证访问(`curl -H "Host: demo.example.com"`) ## 精选 YAML 示例 ```yaml apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: name: apig spec: controllerName: higress.io/gateway-controller --- apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: apig-gateway namespace: default spec: gatewayClassName: apig listeners: - name: http protocol: HTTP port: 80 hostname: "*.example.com" allowedRoutes: namespaces: from: Same --- apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-route namespace: default spec: parentRefs: - name: apig-gateway hostnames: - "demo.example.com" rules: - matches: - path: type: PathPrefix value: / backendRefs: - kind: Service name: httpbin port: 80 ``` ## 参考链接 - [通过云原生 API 网关使用 Gateway API 暴露服务](https://help.aliyun.com/zh/api-gateway/cloud-native-api-gateway/use-cases/expose-services-by-using-the-gateway-api-through-the-cloud-native-api)