Gateway API 企业入口与 Ingress 迁移

验证:未记录
适用版本
未记录
验证范围
尚未登记验证记录。
本文缩写(英文全称与中文含义)
缩写 英文全称/名称 中文含义
API Application Programming Interface 应用程序编程接口
AWS Amazon Web Services 亚马逊云服务
CRD Custom Resource Definition Kubernetes 自定义资源定义
DNS Domain Name System 域名系统
gRPC gRPC Remote Procedure Calls 基于 HTTP/2 的远程过程调用框架
IP Internet Protocol 网际协议;IP 地址是网络寻址标识
PDB Pod Disruption Budget Pod 中断预算,约束自愿驱逐
SLO Service Level Objective 服务等级目标
TLS Transport Layer Security 传输层安全协议
TTL Time To Live 存活时间;具体指缓存有效期或记录过期时间
WAF Web Application Firewall Web 应用防火墙

场景:平台管理 TLS Gateway,团队仅管理获授权的 HTTPRoute。本文选择 Envoy Gateway,AWS 专属入口见 AWS Load Balancer Controller。前置:基线、cert-manager、域名和云 LB 配额。

社区 ingress-nginx 已按官方计划于 2026 年 3 月退休,新部署选择仍维护的控制器;Ingress API 本身并没有因此被移除。官方说明

安装与高可用设计#

固定 Envoy Gateway Chart 及其兼容 Gateway API CRD 版本;先检查集群现有 CRD 的所有者,不能让多个 Chart 覆盖。Envoy Gateway 控制器副本与 Envoy 数据面副本是两套配置。

export EG_VERSION='vREPLACE_VERSION'
helm show values oci://docker.io/envoyproxy/gateway-helm --version "$EG_VERSION" > eg-defaults.yaml

保存 eg-values.yaml,控制器按基线分散到不同节点并配置 PDB;资源值通过吞吐测试调整:

deployment:
  replicas: 2
  envoyGateway:
    resources:
      requests: {cpu: 250m, memory: 256Mi}
      limits: {cpu: "1", memory: 512Mi}
helm upgrade --install eg oci://docker.io/envoyproxy/gateway-helm --version "$EG_VERSION" -n envoy-gateway-system --create-namespace -f eg-values.yaml --wait --timeout 15m
kubectl get crd gateways.gateway.networking.k8s.io httproutes.gateway.networking.k8s.io

保存 edge-gateway.yaml,orders-tls 必须是 edge namespace 中由 Certificate 生成的有效 Secret;EnvoyProxy 调整数据面到 3 副本,进一步在受支持 schema 中配置资源、跨区调度和 PDB。

apiVersion: v1
kind: Namespace
metadata: {name: edge}
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata: {name: edge-proxy, namespace: edge}
spec:
  provider:
    type: Kubernetes
    kubernetes:
      envoyDeployment:
        replicas: 3
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata: {name: enterprise-envoy}
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata: {name: public, namespace: edge}
spec:
  gatewayClassName: enterprise-envoy
  infrastructure:
    parametersRef:
      group: gateway.envoyproxy.io
      kind: EnvoyProxy
      name: edge-proxy
  listeners:
    - name: https
      hostname: orders.staging.example.com
      port: 443
      protocol: HTTPS
      tls:
        mode: Terminate
        certificateRefs: [{name: orders-tls}]
      allowedRoutes:
        namespaces:
          from: Selector
          selector:
            matchLabels: {kubernetes.io/metadata.name: orders}
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata: {name: orders, namespace: orders}
spec:
  parentRefs:
    - {name: public, namespace: edge, sectionName: https}
  hostnames: [orders.staging.example.com]
  rules:
    - matches:
        - path: {type: PathPrefix, value: /}
      backendRefs: [{name: orders-api, port: 80}]

使用所选版本支持 infrastructure.parametersRef 的 API/实现组合;先 server dry-run。云 LB 的公网/私网类型、健康检查、安全组与源 IP 保留在 EnvoyProxy 的 Service 配置中显式确定,禁止依默认值决定生产暴露面。安装、数据面定制

kubectl apply --dry-run=server -f edge-gateway.yaml
kubectl apply -f edge-gateway.yaml
kubectl -n edge get gateway public -o yaml
kubectl -n orders get httproute orders -o yaml
kubectl -n envoy-gateway-system get pods,services -o wide

验收 Gateway Accepted/Programmed=True,Route Accepted/ResolvedRefs=True,证书域名/链正确,LB 后端健康;再经实际域名跑完整业务。若只拿到地址但 Route 被拒绝,不能切 DNS。跨 namespace backend/certificate 引用还需精确 ReferenceGrant,不能开放所有来源。

企业迁移与恢复#

盘点旧 Ingress 的 rewrite、正则、超时、body size、external auth、WAF、WebSocket/gRPC、客户端 IP、TLS 和 cookie affinity;逐项在新入口验证,annotations 不会自动转换。迁移差异

并行新旧入口→用独立预生产域名验证→DNS/LB 小比例切流→观察 SLO→扩大。证书/DNS 由各自控制器唯一管理;不能让 ExternalDNS 同时把同一域名指向两个未经设计的入口。

故障恢复旧 DNS/入口,考虑 TTL、客户端缓存与长连接;保留旧入口至观察期结束。排空一个 Envoy 节点检查连接中断、健康摘流及重试;只对幂等请求开启适当重试,不自动重试扣款。控制面/数据面分别升级,CRD 变更另审核。

搜索文档

输入关键词,搜索所有文档。

↑ ↓ 选择 · Enter 打开 · Esc 关闭