Knative 服务 URL
我目前正在评估 Knative,但我确实找不到使用路径而不是 URL 中的子域来访问服务的方法。
默认情况下,创建服务时,URL 的格式如下: http://Name.Namespace.Domain我想要的是这样的 http://Domain/Namespace/Name
有人知道这是否可能吗? 提前致谢,
塞德里克
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Knative 使用子域而不是 URL 路径,因为底层容器可以处理许多不同的 URL,并且可能使用绝对 URL(可能指向不同的函数,具体取决于部署)或相对 URL(可能指向当前应用程序内)对请求进行编码。
如果您想在单个域名下映射多个 Knative 服务,您可以使用 Ingress 实现或 API 服务器,例如 Kong, Istio,或许多其他。您将需要一个 HTTP 路由器,它可以重写
Host
标头以指向相关 Knative 服务的主机名;默认的 KubernetesIngress
资源不公开此功能。如果您选择进行此设置,您还需要决定映射 URL 路径的策略:您可以在将 URL 路径传递到 Knative 服务时将其剥离,也可以将其保留。去掉 URL 路径可能更有意义,否则您最终将需要应用程序代码与您拥有的
namespace
和name
之间存在依赖关系选择将其部署在。其他需要注意的问题:
DomainMapping
将该 Knative 服务映射到您所需的域名。然后 Knative Service 可以自动进行 URL 重写,如果需要,您可以在出站上进行反向重写。Knative uses subdomains rather than URL paths because the underlying container could handle many different URLs, and might encode requests with absolute URLs (which might point to a different function depending on deployment) or relative URLs (which would point within the current application).
If you want to map multiple Knative services under a single domain name, you can use an Ingress implementation or API server like Kong, Istio, or many others. You will need an HTTP router which can rewrite the
Host
header to point to the Knative Service's hostname in question; the default KubernetesIngress
resource doesn't expose this capability.If you choose to set this up, you'll also need to decide on a policy for mapping the URL paths: you could either strip the URL paths off when passing them to the Knative Service, or leave them present. It probably makes more sense to strip the URL paths off, since otherwise you'll end up needing to have a dependency between your application code and the
namespace
andname
that you have chosen to deploy it at.Other gotchas to watch out for:
DomainMapping
to map that one Knative Service to your desired domain name. The Knative Service could then automatically do the URL rewriting, and you could do the reverse rewriting on the outbound if you wanted.