Re: Exposing Multiple Ports from an Application


Shannon Coen
 

On Wed, Jun 8, 2016 at 5:03 AM, Isuru Haththotuwa <isurulucky(a)gmail.com>
wrote:

Hi Shannon,

Thanks for the reply.

On Wed, Jun 8, 2016 at 4:36 AM, Shannon Coen <scoen(a)pivotal.io> wrote:

If I understand you correctly, you would like your application to receive
requests on multiple ports. Is that correct? Does it matter what ports your
application clients send requests to? Could you please share the details of
your use cases for this functionality?
The usecase is that an application listening to multiple types of traffic
(http, tcp, binary, etc.) from multiple ports exposed in the container.
Therefore I guess we would need to have multiple ports open from the host
side as well.
If your application receives http traffic on more than one port, you would
not need another port opened, only another route. For non-HTTP traffic, you
would need a TCP route (with a reserved port) for each app port. The route
ports will not match your application ports. Does this sound like it would
fulfill your needs?



Currently HTTP requests may only be sent to 80 or 443. Your app may
receive requests on one port only. On DEAs, this port is randomized and can
be discovered from the $PORT env var. On Diego, this env var is also
present but is always 8080.

This isn't a limitation of Diego; Diego will open whatever container
ports a client tells it to. However, we have not yet added the business
logic to Cloud Controller to expose management of these ports to
application developers.

You discovered that two ports are already opened on the container. The
second port is opened automatically in support of the feature that enables
a developer to SSH into the container. The env var you identified, CF_INSTANCE_PORTS,
is a list of all ports opened on the container. This env var should be
considered an internal implementation detail as it contains ports used by
internal system components to which an app should not bind. The env var is
documented as there are a few use cases where an app needs to know what the
host port is.

We do plan to enable applications to listen on multiple ports. Clients
will still make HTTP requests to 80 or 443, but a developer will be able to
specify the application port when mapping a route to an application.

E.g.
myapp.cf.com -> myapp listening on 8080
myapp.cf.com/admin -> myapp listening on 6000

I'm currently drafting a proposal for this feature and will share it soon
for feedback.
This is indeed great news!


If your clients must call your application on a port besides 80 or 443, I
would recommend exploring our support for TCP routing (see the CLI help
file for create-route). Developers can reserve non-standard ports for a
route, like tcp.cf.com:6000, and CF will route requests for it to your
application port on 8080. After we deliver support for custom app ports, as
described above, you would be able to specify both the route port and the
app port.





Shannon Coen
Product Manager, Cloud Foundry
Pivotal, Inc.

On Tue, Jun 7, 2016 at 1:18 AM, Isuru Haththotuwa <isurulucky(a)gmail.com>
wrote:

Hi all,

Is it possible to expose two ports of an Application via from CF to
external traffic, via an externally routable address and multiple ports?

While going through the documentation, came across [1], which suggests
that requests are served from port 80 and 443 only. However, while trying
out the sample spring application [2] on CF (using the hosted CF in pivotal
web services), I could actually see that there are multiple port mappings
defined by invoking the rest API [3]. Additionally, in pivotal.io docs,
I see the definition of CF-INSTANCE-PORTS, which seems to support multiple
port mappings from host to container.

I'm curios to know if exposing multiple ports from the host and
container side is possible.

Thanks in advance.

[1].
https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#ports

[2]. https://github.com/cloudfoundry-samples/spring-music

[3].
{
"0": {
"state": "RUNNING",
"stats": {
"name": "spring-music",
"uris": [
"spring-music-moonlit-melioration.cfapps.io"
],
"host": "10.10.115.53",
"port": 64248,
"net_info": {
"address": "10.10.115.53",
* "ports": [*
* {*
* "container_port": 8080,*
* "host_port": 64248*
* },*
* {*
* "container_port": 2222,*
* "host_port": 64249*
* }*
* ]*
},
"uptime": 9484,
"mem_quota": 536870912,
"disk_quota": 1073741824,
"fds_quota": 16384,
"usage": {
"time": "2016-05-20T11:12:38.944471672Z",
"cpu": 0.0010850797743361504,
"mem": 460423168,
"disk": 166739968
}
}
}
}

[4].
http://docs.run.pivotal.io/devguide/deploy-apps/environment-variable.html#CF-INSTANCE-PORTS


--
Thanks and Regards,
Isuru

Join cf-dev@lists.cloudfoundry.org to automatically receive all group messages.