
一文搞懂 Kubernetes Gateway API 的 Policy Attachment
背景 在《SMI 与 Gateway API 的 GAMMA 倡议意味着什么?》的一文中,介绍过 Kubernetes Gateway API 处理东西向(网格)流量的可能性。让我们重新看下 Gateway API 中对流量定义(路由)的定义,以 HTTP 路由为例: apiVersion: gateway.networking.k8s.io/v1beta1 kind: HTTPRoute metadata: name: my-route namespace: gateway-api-example-ns2 spec: parentRefs: - kind: Gateway name: foo-gateway namespace: gateway-api-example-ns1 hostnames: - foo.example.com rules: - backendRefs: - name: foo-svc port: 8080 上面的 YAML 中,使用 parentRefs 字段将路由策略附加到了网关资源 foo-gateway 上。网关 foo-gateway 会根据请求头部的 HOST 来选择合适的 HTTPRoute,然后将流量代理到上游 Service foo-svc。简单来说,就是定义了“网关 -> 路由 -> 后端”的映射。