英文:
Redirecting HTTP to HTTPS with GKE Gateway and HTTPRessource
问题
以下是您要翻译的内容:
在查看入口选项时,我们发现Gateway资源在纸上与传统的nginx入口或托管入口相比,更适合我们(因为后者需要为每个入口配置一个负载均衡器)。
在弄清楚Gateways和HTTPRoutes的语法后,我已经成功实现了我想要的大部分功能,但我在HTTP->HTTPS重定向上遇到了困难。在常规的入口上,只需在FrontendConfig中设置redirectToHttps,根据k8s API文档,通过HTTPRoute中的RequestRedirect过滤器应该也可以实现相同的效果。
但事实上,GKE上似乎没有支持或实现此功能。但我仍然需要以某种方式重定向HTTP到HTTPS请求。虽然我确信有各种方法可以做到这一点,但我正在寻找一种不太繁琐的方法。
官方文档中的这个基本HTTPRoute示例在GKE上会产生错误。
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: http-filter-redirect
spec:
hostnames:
- redirect.example
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301
错误信息:GWCER104: HTTPRoute "default/http-filter-redirect" 配置错误,错误:不支持的过滤器类型:RequestRedirect。
根据Google GatewayClass文档,requestRedirect过滤器不可用。
英文:
Looking at ingress options we've found that the Gateway ressource was on paper the better fit for us compared to traditional nginx Ingresses or managed Ingresses (since those need to provision one LB for every one ingress).
After wrapping my head around the grammar of Gateways and HTTPRoutes, I've managed to achieve most of what I wanted to but I'm getting stuck on HTTP->HTTPS redirections. On a regular Ingress it's just a matter of setting redirectToHttps in a FrontendConfig, and as per the k8s API documentation the same should be achievable through a RequestRedirect filter in the HTTPRoute.
As it happens, there doesn't seem to be any support or implementation of this feature on GKE. But I still need to redirect HTTP to HTTPS requests somehow. While I'm sure there are ways of doing it, I'm looking for one that's not too hacky.
This basic HTTPRoute example from the official documentation produces an error on GKE.
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: http-filter-redirect
spec:
hostnames:
- redirect.example
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301
Error GWCER104: HTTPRoute "default/http-filter-redirect" is misconfigured, err: unsupported filter type: RequestRedirect.
As per the Google documentation of GatewayClass, the requestRedirect filter is not available.
答案1
得分: 2
已支持在GA中。
apiVersion: v1
kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: redirect
namespace: gateway-infra
spec:
parentRefs:
- namespace: gateway-infra
name: external-http
sectionName: http
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
更多信息请参考:https://cloud.google.com/kubernetes-engine/docs/how-to/deploying-gateways#configure_http-to-https_redirects
英文:
It is supported in GA now.
apiVersion: v1
kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: redirect
namespace: gateway-infra
spec:
parentRefs:
- namespace: gateway-infra
name: external-http
sectionName: http
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
答案2
得分: 0
目前看来,GKE中网关资源的HTTPRoute API
似乎不支持requestRedirect filter
。请打开一个问题跟踪器,并将此作为潜在的功能请求提交。请使用提供的链接提交您的功能请求。
英文:
Currently, it appears that the HTTPRoute API
for the Gateway resource in GKE does not support the requestRedirect filter
. Kindly open an issue tracker and submit this as a potential feature request for now. Please use the provided link to submit your feature request.
答案3
得分: 0
HTTP 到 HTTPS 的重定向仍然不受我们的网关控制器支持。有关支持的功能的完整列表,请查看此页面 https://cloud.google.com/kubernetes-engine/docs/how-to/gatewayclass-capabilities
并保持关注。在支持重定向时,它将会更新。
英文:
HTTP to HTTPS redirect is still not supported by our Gateway Controller. For a full list of supported features take a look at this page https://cloud.google.com/kubernetes-engine/docs/how-to/gatewayclass-capabilities
And keep an eye on it. It will be updated when the redirect is supported.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论