Routes

You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]

You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]

Overview

An OKD route exposes a service at a host name, like www.example.com, so that external clients can reach it by name.

DNS resolution for a host name is handled separately from routing; your administrator may have configured a cloud domain that will always correctly resolve to the OKD router, or if using an unrelated host name you may need to modify its DNS records independently to resolve to the router.

Creating Routes

You can create unsecured and secured routes using the web console or the CLI.

Using the web console, you can navigate to the Routes page, found under the Applications section of the navigation.

Click Create Route to define and create a route in your project:

Creating a Route Using the Web Console

Figure 1. Creating a Route Using the Web Console

Using the CLI, the following example creates an unsecured route:

  1. $ oc expose svc/frontend --hostname=www.example.com

The new route inherits the name from the service unless you specify one using the --name option.

YAML Definition of the Unsecured Route Created Above

  1. apiVersion: v1
  2. kind: Route
  3. metadata:
  4. name: frontend
  5. spec:
  6. host: www.example.com
  7. path: "/test" (1)
  8. to:
  9. kind: Service
  10. name: frontend
1For path-based routing, specify a path component that can be compared against a URL.

For information on configuring routes using the CLI, see Route Types.

Unsecured routes are the default configuration, and are therefore the simplest to set up. However, secured routes offer security for connections to remain private. To create a secured HTTPS route encrypted with a key and certificate (PEM-format files which you must generate and sign separately), you can use the create route command and optionally provide certificates and a key.

TLS is the replacement of SSL for HTTPS and other encrypted protocols.

  1. $ oc create route edge --service=frontend \
  2. --cert=${MASTER_CONFIG_DIR}/ca.crt \
  3. --key=${MASTER_CONFIG_DIR}/ca.key \
  4. --ca-cert=${MASTER_CONFIG_DIR}/ca.crt \
  5. --hostname=www.example.com

YAML Definition of the Secured Route Created Above

  1. apiVersion: v1
  2. kind: Route
  3. metadata:
  4. name: frontend
  5. spec:
  6. host: www.example.com
  7. to:
  8. kind: Service
  9. name: frontend
  10. tls:
  11. termination: edge
  12. key: |-
  13. -----BEGIN PRIVATE KEY-----
  14. [...]
  15. -----END PRIVATE KEY-----
  16. certificate: |-
  17. -----BEGIN CERTIFICATE-----
  18. [...]
  19. -----END CERTIFICATE-----
  20. caCertificate: |-
  21. -----BEGIN CERTIFICATE-----
  22. [...]
  23. -----END CERTIFICATE-----

Currently, password protected key files are not supported. HAProxy prompts for a password upon starting and does not have a way to automate this process. To remove a passphrase from a keyfile, you can run:

  1. # openssl rsa -in <passwordProtectedKey.key> -out <new.key>

You can create a secured route without specifying a key and certificate, in which case the router’s default certificate will be used for TLS termination.

TLS termination in OKD relies on SNI for serving custom certificates. Any non-SNI traffic received on port 443 is handled with TLS termination and a default certificate, which may not match the requested host name, resulting in validation errors.

Further information on all types of TLS termination as well as path-based routing are available in the Architecture section.

Allowing Route Endpoints to Control Cookie Names

OKD provides sticky sessions, which enables stateful application traffic by ensuring all traffic hits the same endpoint. However, if the endpoint pod terminates, whether through restart, scaling, or a change in configuration, this statefulness can disappear.

OKD can use cookies to configure session persistence. The router selects an endpoint to handle any user requests, and creates a cookie for the session. The cookie is passed back in the response to the request and the user sends the cookie back with the next request in the session. The cookie tells the router which endpoint is handling the session, ensuring that client requests use the cookie so that they are routed to the same pod.

You can set a cookie name to overwrite the default, auto-generated one for the route. By deleting the cookie it can force the next request to re-choose an endpoint. So, if a server was overloaded it tries to remove the requests from the client and redistribute them.

  1. Annotate the route with the desired cookie name:

    1. $ oc annotate route <route_name> router.openshift.io/cookie_name="<your_cookie_name>"

    For example, to specify my_cookie as your new cookie name:

    1. $ oc annotate route my_route router.openshift.io/cookie_name="my_cookie"
  2. Save the cookie, and access the route:

    1. $ curl $my_route -k -c /tmp/my_cookie