端口绑定 - 12 Factor App

Port Binding - 12 Factor App

每当我部署 spring 启动应用程序时,它都会嵌入 tomcat 容器。它依赖于可用的容器。这是否意味着这些不符合 12 因素应用程序,因为取决于网络服务器的运行时注入?

TCP 路由对于非 http 服务意味着什么?

Port Binding

Export services via port binding. The 12-factor app is completely self-contained and does not rely on runtime injection of a web server into the execution environment to create web-facing service.

For Pivotal Cloud Foundry, non-HTTP services require TCP routing in order to be replatformed.

当您 运行 在本地 spring 启动应用程序时,它 运行 带有 default 配置文件。因此,Spring 将在 运行 时利用您的端口和其他设置。

当您推送到云时,spring 启动应用程序 运行 具有 cloud 配置文件。在 cloud 配置文件中,端口设置由云决定,您提供的设置将被忽略。

在 PCF 中,Diego 单元托管所有应用程序实例。 Diego 单元有自己的 CIDR 块,用于托管应用程序。因此,您的应用程序实例将从该范围内获取一个 IP。并且您无法通过其 ip 访问该应用程序。

Diego cell vm 拥有来自其 运行ning 网络 CIDR 范围的 IP。 Diego cell 还使用 NAT-ing 将您的应用程序 ip 映射到 Diego cell vm 上的端口。这就是将流量路由到您的应用程序的方式。

如您所见,PCF 中的 Diego 单元不能依赖您提供的端口。相反,它将 运行 尽可能地应用程序,并将 NAT 连接到可用端口。

看看Diego Reference Architecture

关于你的第二个问题,Cloud Foundry 中的 Go-Routers 将请求路由到应用程序实例。默认情况下,Go-Routers 仅启用 http/https 流量。您可以在 Go-Router 上启用 TCP 路由。我相信这是在 PCF 1.9 中添加的。 这是 documentation.