forked from cloudfoundry/docs-dev-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-ports.html.md.erb
107 lines (67 loc) · 5.42 KB
/
custom-ports.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: Configuring CF to Route Traffic to Apps on Custom Ports
owner: CF for VMs Networking
---
<% current_page.data.title = "Configuring " + vars.app_runtime_abbr + " to Route Traffic to Apps on Custom Ports" %>
This topic describes how to configure <%= vars.app_runtime_first %> to route traffic to your apps listening on custom ports.
## <a id="overview"></a> Overview
By default, apps only receive requests on port 8080 for both HTTP and TCP routing, and so must be configured, or hardcoded, to listen on this port. Configuring custom app ports allows developers to bring workloads onto <%= vars.app_runtime_abbr %> that listen on ports other than 8080. Some example use cases are:
* Serving web client requests on one port and offering stats/debug on another
* Using TCP protocols that require multiple ports
* Running Docker images on <%= vars.app_runtime_abbr %>
The procedure below describes how to use the `apps` and `route_mappings` Cloud Controller API endpoints to update the ports the app can receive requests on.
### <a id="flow"></a> Flow of a Request to an App
The following table describes the Network Address Translation that occurs in the data path of a client request. The procedure in this document discusses configuring _app ports_ specifically.
| Port Type | Description | Network Hop |
| --------- | ----------- | ----------- |
| Route port | The port a client sends a request to | Client to load balancer, load balancer to Gorouter |
| Back end port | The port on the VM where an app container is hosted, which is unique to the container | Gorouter to Diego Cell |
| App port | The port on the container; this must match a port the app is configured to listen on | Diego Cell to app container |
The following diagram provides an example data path and Network Address Translation for TCP routing. For HTTP routing, the route port is always 80 or 443.

## <a id="prerequisite"></a> Prerequisites
Before following the procedure to configure routing to your app on custom ports, you must have:
* An app pushed to <%= vars.app_runtime_abbr %> that can listen on one or more custom ports.
* Routes for which you want traffic forwarded to your app on custom ports.
* If your app listens on two ports and you want clients to be able to send requests to both of them, create two routes. These can be from HTTP or TCP domains. Consider an example in which you have two routes: `foo.example.com` and `bar.example.com`. In the following procedure, you use API endpoints to map these routes to your app on the ports it is listening. For more information, see [Routes and Domains](./deploy-apps/routes-domains.html).
## <a id="procedure"></a> Procedure
To configure your app to receive HTTP or TCP traffic on custom ports:
1. Retrieve the GUID of your app by running:
```
cf app APP-NAME --guid
```
Where `APP-NAME` is the name of your app.
1. Configure <%= vars.app_runtime_abbr %> with the ports your app is listening on by running:
```
cf curl /v2/apps/APP-GUID -X PUT -d '{"ports": [PORT1, PORT2, PORT3...]}'
```
Where:
* `APP-GUID` is the GUID of your app.
* `PORT1, PORT2, PORT3...` is a comma-separated list of the ports on which you want your app to receive traffic.
1. Retrieve the GUID of the route to which clients make requests, and for which <%= vars.app_runtime_abbr %> routes requests to the app on a custom port. Use one of the following options:
- For a TCP route with a hostname, retrieve its GUID by running:
```
cf curl /v2/routes?q=host:HOST-NAME
```
Where `HOST-NAME` is the hostname for the route. By default, this is the name of your app.
- For a TCP route without a hostname, retrieve its GUID by running:
```
cf curl /v2/apps/APP-GUID/routes
```
1. Check and update the route mappings for your app by running:
```
cf curl /v2/routes/ROUTE-GUID/route_mappings
cf curl /v2/route_mappings -X POST -d '{"app_guid": "APP-GUID", "route_guid": "ROUTE-GUID", "app_port": PORT1}'
```
Where:
* `APP-GUID` is the GUID of your app.
* `ROUTE-GUID` is the GUID of the route at which the app serves.
* `PORT1` is the app port, or one of the app ports, that you added in the previous step.
1. Repeat the previous two steps for each port that you want your app to receive requests on.
<p class="note"><strong>Note:</strong> If you are trying to remove an app port, you need to delete the associated route mapping before you can update the app to remove the port.</p>
## <a id="additional-resources"></a> Additional Resources
For additional resources related to configuring custom app ports:
* For more information about making requests to the Cloud Controller `apps` endpoint, see [Updating an App](https://apidocs.cloudfoundry.org/6.10.0/apps/updating_an_app.html) in the Cloud Controller API documentation.
* For more information about making requests to the Cloud Controller `route_mappings` endpoint, see [Mapping an App and a Route](https://apidocs.cloudfoundry.org/6.10.0/routes_mapping/mapping_an_app_and_a_route.html) in the Cloud Controller API documentation.
* For an example multi-port app, see the [cf-acceptance-tests](https://github.com/cloudfoundry/cf-acceptance-tests/tree/develop/assets/multi-port-app) repository on GitHub.
* For a demo procedure written by an open source CF user, see the ["Multiple App Ports" Demo on Cloud Foundry](https://gist.github.com/nota-ja/ef56ea0584ae2b37d6d3a535efe2d4ee) on GitHub.