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

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

URL Redirect / Rewrite on GKE Gateway and HTTPRoute

问题

我的Gateway和HTTPRoute配置如下:

  1. apiVersion: gateway.networking.k8s.io/v1beta1
  2. kind: Gateway
  3. metadata:
  4. name: external-http
  5. spec:
  6. gatewayClassName: gke-l7-global-external-managed
  7. listeners:
  8. - name: https
  9. protocol: HTTPS
  10. port: 443
  11. tls:
  12. mode: Terminate
  13. options:
  14. networking.gke.io/pre-shared-certs: "my-certificate-name"
  15. - name: http
  16. protocol: HTTP
  17. port: 80
  1. apiVersion: gateway.networking.k8s.io/v1beta1
  2. kind: HTTPRoute
  3. metadata:
  4. name: my-route
  5. spec:
  6. parentRefs:
  7. - kind: Gateway
  8. name: external-http
  9. hostnames:
  10. - "example.com"
  11. rules:
  12. - backendRefs:
  13. - name: frontend
  14. port: 80
  15. - matches:
  16. - path:
  17. type: PathPrefix
  18. value: /api
  19. filters:
  20. - type: URLRewrite
  21. urlRewrite:
  22. path:
  23. type: ReplacePrefixMatch
  24. replacePrefixMatch: /
  25. backendRefs:
  26. - name: backend
  27. 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:

  1. apiVersion: gateway.networking.k8s.io/v1beta1
  2. kind: Gateway
  3. metadata:
  4. name: external-http
  5. spec:
  6. gatewayClassName: gke-l7-global-external-managed
  7. listeners:
  8. - name: https
  9. protocol: HTTPS
  10. port: 443
  11. tls:
  12. mode: Terminate
  13. options:
  14. networking.gke.io/pre-shared-certs: "my-certificate-name"
  15. - name: http
  16. protocol: HTTP
  17. port: 80

And my HTTPRoute:

  1. apiVersion: gateway.networking.k8s.io/v1beta1
  2. kind: HTTPRoute
  3. metadata:
  4. name: my-route
  5. spec:
  6. parentRefs:
  7. - kind: Gateway
  8. name: external-http
  9. hostnames:
  10. - "example.com"
  11. rules:
  12. - backendRefs:
  13. - name: frontend
  14. port: 80
  15. - matches:
  16. - path:
  17. type: PathPrefix
  18. value: /api
  19. filters:
  20. - type: URLRewrite
  21. urlRewrite:
  22. path:
  23. type: ReplacePrefixMatch
  24. replacePrefixMatch: /
  25. backendRefs:
  26. - name: backend
  27. 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:

确定