Knative 服务 URL

发布于 2025-01-09 21:59:56 字数 257 浏览 0 评论 0 原文

我目前正在评估 Knative,但我确实找不到使用路径而不是 URL 中的子域来访问服务的方法。

默认情况下,创建服务时,URL 的格式如下: http://Name.Namespace.Domain我想要的是这样的 http://Domain/Namespace/Name

有人知道这是否可能吗? 提前致谢,

塞德里克

I'm currently evaluating Knative but I've definitely find no way to use path instead of subdomain in the URL for accessing service.

By default, when creating an service, the URL is made like this: http://Name.Namespace.Domain and what I would like to have is something like this http://Domain/Namespace/Name

Does anybody knows if it is possible ?
Thanks in advance,

Cédric

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法少女 2025-01-16 21:59:56

Knative 使用子域而不是 URL 路径,因为底层容器可以处理许多不同的 URL,并且可能使用绝对 URL(可能指向不同的函数,具体取决于部署)或相对 URL(可能指向当前应用程序内)对请求进行编码。

如果您想在单个域名下映射多个 Knative 服务,您可以使用 Ingress 实现或 API 服务器,例如 Kong, Istio,或许多其他。您将需要一个 HTTP 路由器,它可以重写 Host 标头以指向相关 Knative 服务的主机名;默认的 Kubernetes Ingress 资源不公开此功能。

如果您选择进行此设置,您还需要决定映射 URL 路径的策略:您可以在将 URL 路径传递到 Knative 服务时将其剥离,也可以将其保留。去掉 URL 路径可能更有意义,否则您最终将需要应用程序代码与您拥有的 namespacename 之间存在依赖关系选择将其部署在。

其他需要注意的问题:

  • 由于所有 Knative 服务都位于单个主机名后面,因此它们将共享相同的 cookie 域,并且可能会无意中破坏或毒害彼此的 cookie。
  • 正如我上面提到的,绝对 URL 引用与相对 URL 引用。您的 HTTP 路由器可能无法在出站路径上重新添加剥离的 URL 前缀;如果您的 URL 是用 HTML 或 Javascript 构建的,而不是简单地在 URL 标头中构建的,则情况会加倍。
  • 创建新服务时自动对 HTTP 路由器进行编程并不是自动化的——您需要自己执行此操作。您还可以编写 Knative 服务来执行此路由并使用 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 Kubernetes Ingress 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 and name that you have chosen to deploy it at.

Other gotchas to watch out for:

  • Since all the Knative Services are behind a single hostname, they'll share the same cookie domain, and could inadvertently stomp or poison each others cookies.
  • Absolute vs relative URL references, as I mentioned above. It's likely that your HTTP router doesn't have the ability to re-add the stripped URL prefix on outbound paths; doubly so if you have URLs which are being constructed in HTML or Javascript, rather than simply in URL headers.
  • Automatically programming your HTTP router as new Services are created is not automated -- you'd need to do this yourself. You could also write a Knative Service to do this routing and use a 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文