Skip to main content

Overview

The Route class represents an OpenShift Route object, which exposes a service at a host name so that external clients can reach it by name. Routes are OpenShift-specific resources that provide advanced features like TLS termination, load balancing, and custom routing. Source: ocp_resources/route.py:5

Class Definition

from ocp_resources.route import Route

class Route(NamespacedResource):
    api_group = NamespacedResource.ApiGroup.ROUTE_OPENSHIFT_IO

Constructor

Route(
    name=None,
    namespace=None,
    client=None,
    service=None,
    destination_ca_cert=None,
    teardown=True,
    yaml_file=None,
    delete_timeout=TIMEOUT_4MINUTES,
    **kwargs
)

Parameters

name
str
default:"None"
Name of the Route resource. If not provided, it must be specified in the YAML file.
namespace
str
default:"None"
Namespace where the Route will be created. Required for namespaced resources.
client
DynamicClient
default:"None"
Kubernetes dynamic client for API communication. If not provided, the default client will be used.
service
str
default:"None"
Name of the Service to expose through this Route. This creates a route targeting the specified service.
destination_ca_cert
str
default:"None"
CA certificate for TLS re-encrypt termination. When provided, the route will be configured with re-encrypt TLS termination.
teardown
bool
default:"True"
If True, the resource will be automatically deleted when used as a context manager.
yaml_file
str
default:"None"
Path to a YAML file containing the Route definition. If provided, the Route will be created from this file.
delete_timeout
int
default:"TIMEOUT_4MINUTES"
Timeout in seconds for delete operations. Defaults to 4 minutes.
**kwargs
Any
Additional keyword arguments passed to the parent NamespacedResource class. Common options include label and annotations.

Properties

exposed_service

@property
def exposed_service(self) -> str
Returns the name of the service that the route is exposing. Source: ocp_resources/route.py:48 Returns: Service name as a string

host

@property
def host(self) -> str
Returns the hostname that is exposing the service externally. Source: ocp_resources/route.py:55 Returns: Host name as a string

ca_cert

@property
def ca_cert(self) -> str
Returns the destination CA certificate used for TLS termination. Source: ocp_resources/route.py:62 Returns: CA certificate as a string

termination

@property
def termination(self) -> str
Returns the TLS termination type for a secured route (e.g., “edge”, “passthrough”, “reencrypt”). Source: ocp_resources/route.py:69 Returns: Termination type as a string

Usage Examples

Basic Route Creation

Create a simple route that exposes a service:
from ocp_resources.route import Route

route = Route(
    name="my-app-route",
    namespace="default",
    service="my-app-service"
)
route.deploy()

print(f"Route exposed at: {route.host}")

Secure Route with TLS Re-encryption

Create a route with re-encrypt TLS termination:
from ocp_resources.route import Route

ca_certificate = """-----BEGIN CERTIFICATE-----
MIIC...
-----END CERTIFICATE-----"""

route = Route(
    name="secure-app-route",
    namespace="default",
    service="secure-app-service",
    destination_ca_cert=ca_certificate
)
route.deploy()

print(f"Secure route: {route.host}")
print(f"TLS termination: {route.termination}")

Using Context Manager

Automatically clean up the route after use:
from ocp_resources.route import Route

with Route(
    name="temp-route",
    namespace="default",
    service="temp-service"
) as route:
    print(f"Temporary route created: {route.host}")
    # Route is automatically deleted when exiting the context

Creating from YAML

Create a route from a YAML file:
from ocp_resources.route import Route

route = Route(
    namespace="default",
    yaml_file="route-definition.yaml"
)
route.deploy()

Accessing Route Properties

Query route properties after creation:
from ocp_resources.route import Route

route = Route(
    name="my-route",
    namespace="default"
)

if route.exists:
    print(f"Exposed service: {route.exposed_service}")
    print(f"External host: {route.host}")
    if hasattr(route.instance.spec, 'tls'):
        print(f"TLS termination: {route.termination}")
        print(f"CA certificate: {route.ca_cert}")

OpenShift-Specific Features

Route Types

  • Unsecured Routes: Basic HTTP routes without TLS
  • Edge Termination: TLS terminates at the router, traffic to backend is HTTP
  • Passthrough Termination: Encrypted traffic passes through to the backend
  • Re-encrypt Termination: TLS terminates at router, re-encrypts to backend

Wildcard Routes

Routes support wildcard subdomains for multi-tenant applications:
spec:
  host: "*.apps.example.com"

Route Annotations

Common annotations for route behavior:
  • haproxy.router.openshift.io/timeout: Set custom timeout
  • haproxy.router.openshift.io/rate-limit-connections: Rate limiting
  • haproxy.router.openshift.io/balance: Load balancing algorithm

See Also

Build docs developers (and LLMs) love