URL重定向/重写在GKE网关和HTTPRoute上

huangapple go评论75阅读模式
英文:

URL Redirect / Rewrite on GKE Gateway and HTTPRoute

问题

我的Gateway和HTTPRoute配置如下:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
  name: external-http
spec:
  gatewayClassName: gke-l7-global-external-managed
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    tls:
      mode: Terminate
      options:
        networking.gke.io/pre-shared-certs: "my-certificate-name"
  - name: http
    protocol: HTTP
    port: 80
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: my-route
spec:
  parentRefs:
  - kind: Gateway
    name: external-http
  hostnames:
  - "example.com"
  rules:
  - backendRefs:
    - name: frontend
      port: 80
  - matches:
    - path:
        type: PathPrefix
        value: /api
    filters:
    - type: URLRewrite
      urlRewrite:
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: /
    backendRefs:
    - name: backend
      port: 80

我想要的是将任何在/api下的请求路由到我的后端应用程序,但我希望它们被重写为/。

尽管我配置了所有这些内容,但我的路由没有被重写,当我查看HTTPRoute的事件时,显示以下错误:

failed: Error GWCER104: HTTPRoute "default/my-route" is misconfigured, err: unsupported filter type: URLRewrite.

我已经按照Google的指南设置了URL重定向,并且我不明白为什么会出现这个错误。
https://cloud.google.com/kubernetes-engine/docs/how-to/deploying-gateways#configure_url_rewrites

根据Google文档,我正在使用的Gateway类应该支持URL重定向。
https://cloud.google.com/kubernetes-engine/docs/how-to/gatewayclass-capabilities?hl=en

我的集群版本是1.27.2-gke.2100

在Google文档中说URLRewrite不受支持的情况下,我为什么会收到错误消息?

英文:

I am attempting to set up a gateway on the Google Kubernetes Engine, where I would like to rewrite requests at /api, but I am unable to get it to work.

My Gateway is configured as follows:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
  name: external-http
spec:
  gatewayClassName: gke-l7-global-external-managed
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    tls:
      mode: Terminate
      options:
        networking.gke.io/pre-shared-certs: "my-certificate-name"
  - name: http
    protocol: HTTP
    port: 80

And my HTTPRoute:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: my-route
spec:
  parentRefs:
  - kind: Gateway
    name: external-http
  hostnames:
  - "example.com"
  rules:
  - backendRefs:
    - name: frontend
      port: 80
  - matches:
    - path:
        type: PathPrefix
        value: /api
    filters:
    - type: URLRewrite
      urlRewrite:
        path:
          type: ReplacePrefixMatch
          replacePrefixMatch: /
    backendRefs:
    - name: backend
      port: 80

What I want to do is route any requests at /api to my backend application, but I want them to be rewritten to /.

With all this configuration my routes are not getting rewritten and when I look at the events of my HTTPRoute it shows the following error:

failed: Error GWCER104: HTTPRoute "default/my-route" is misconfigured, err: unsupported filter type: URLRewrite.

I have followed the guide from google to set up URL redirects, and I don't see what I would be doing differently that would cause this error.
https://cloud.google.com/kubernetes-engine/docs/how-to/deploying-gateways#configure_url_rewrites

According to the google docs the gateway class I am using should support URL Redirects
https://cloud.google.com/kubernetes-engine/docs/how-to/gatewayclass-capabilities?hl=en

My cluster is on version 1.27.2-gke.2100

Why would I be getting an error that URLRewrite is unsupported when in the Google documentation it says it should be?

答案1

得分: 1

根据错误消息显示,基于 GKE 网关的 HTTPRoute 中的 URLRewrite 不受支持。从同一文档中可以看出,GKE 版本尚未受到支持。

我建议您打开问题跟踪器并将此问题提交为功能请求。

英文:

The URLRewrite in your HTTPRoute on GKE gate based on the error message is not supported. From the same documentation it shows that the GKE version is not yet supported.

I would like to suggest open issue tracker and submit concern as a feature request.

huangapple
  • 本文由 发表于 2023年7月18日 04:43:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定