Chapter 4. Exposing Services

Most cartridges provide services by binding to ports. Cartridges must declare to which ports they bind, and provide variable names to describe:
  • The IP addresses provided to the cartridge for binding.
  • The local gear ports to which the cartridge services bind.
  • (Optional) The public proxy ports that expose local gear ports for communication between related gears in an application, such as the TCP proxy public endpoint.
  • (Optional) TCP endpoint mappings that establish a front end for application users.

4.1. TCP Endpoints

TCP endpoints are services that are exposed by a cartridge, and are accessible by other cartridges or gears in an application. They may be any protocol which uses TCP, such as http or mysql. These services may also be exposed to application users through mappings. OpenShift Enterprise only creates endpoint ports for scalable applications.
The endpoints can be defined in the Endpoints section of the $cartridge_name/metadata/manifest.yml file.

Example 4.1. Endpoints Entry

Endpoints:
  - Private-IP-Name:   <name of IP variable>
    Private-Port-Name: <name of port variable>
    Private-Port:      <port number>
    Public-Port-Name:  <name of public port variable>
    Protocols:         [<protocol type 1>,<protocol type 2>]
    Mappings:
      - Frontend:      '<frontend path>'
        Backend:       '<backend path>'
        Options:       { ... }
      - <...>
  - <...>
When a cartridge is installed on a gear, it automatically assigns IP addresses to each IP variable name ensuring that assigned addresses can bind to the specified port.
If an endpoint specifies a public port variable, a public port proxy mapping is created using a random external port accessible through the gear's DNS entry.
Endpoint Environment Variables

Endpoint values are exposed to cartridge scripts and application code through environment variables. These environment variables are formed from the Cartridge-Short-Name element and from the endpoint variable names specified in the manifest.yml file.

Example 4.2. Environment Variable Format

OPENSHIFT_{Cartridge-Short-Name}_{name of IP variable}          => <assigned internal IP>
OPENSHIFT_{Cartridge-Short-Name}_{name of port variable}        => <endpoint specified port>
OPENSHIFT_{Cartridge-Short-Name}_{name of public port variable} => <assigned external port>
Endpoint Protocols

You can define the protocols for services using the Protocols variable. Protocols takes a comma-separated list of protocol types from the following available options:

Table 4.1. Endpoint Protocols

Protocol Description
tcp TCP
http HTTP
https HTTP Secure (HTTP over SSL/TLS)
ws WebSocket
wss WebSocket Secure (WebSocket over SSL/TLS)
tls SNI Proxy
mongodb MongoDB
mysql MySQL
postgresql PostgreSQL
If the Protocols list is not set, the default behavior matches the pre-Protocols behavior. For example, if an endpoint has Mappings, assume HTTP; otherwise, assume TCP. The front-end modules also translate Mappings options. For example, if a Mappings entry has websocket set in its Options, then ws is added to the Protocols list.
Endpoint Mappings

If an endpoint specifies Mappings, a front-end httpd route to the cartridge is created for each mapping entry using the provided options. The Frontend key is a front-end path element connected to a back-end URI specified by the Backend key. The Options hash enables additional route configuration options.

Table 4.2. Endpoint Mapping Options

Option Description
websocket Enable WebSocket on a particular path
gone Mark the path as gone (URI is ignored)
forbidden Mark the path as forbidden (URI is ignored)
noproxy Mark the path as not proxied (URI is ignored)
redirect Use redirection to URI instead of proxy (URI must be a path)
file Ignore request and load file path contained in URI (must be a path)
tohttps Redirect request to HTTPS and use the path contained in the URI (must be a path)