Kahibaro
Discord Login Register

Routes and ingress

Understanding Routes and Ingress in OpenShift

In OpenShift, exposing services externally is handled primarily through Routes and, in newer versions, through Kubernetes Ingress and OpenShift Route-based ingress controllers. This chapter focuses on how these mechanisms work, how they differ, and when to use which.

Role of Routes vs Ingress in OpenShift

OpenShift historically introduced its own abstraction, the Route, before Kubernetes had Ingress. Today you will encounter:

At a high level:

OpenShift Routes: Core Concepts

A Route maps an external DNS host name to a Service inside the cluster. The router (ingress controller) receives incoming traffic, matches the host/path, and forwards to the appropriate Service and then Pods.

Key fields of a Route resource:

Example basic Route:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: myapp
spec:
  host: myapp.apps.example.com
  to:
    kind: Service
    name: myapp
  port:
    targetPort: http

After creation:

Route Creation Methods

You typically create Routes by:

Example with oc expose:

oc expose service myapp --hostname=myapp.apps.example.com

This creates a Route pointing to the myapp Service with the given host.

TLS Termination in Routes

One of the most important aspects of Routes is TLS/HTTPS handling. OpenShift routers support three main TLS termination types:

  1. Edge termination
  2. Passthrough termination
  3. Re-encrypt termination

Each has different implications for security, certificate management, and application behavior.

Edge Termination

Use when:

Example:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: myapp-edge
spec:
  host: myapp.apps.example.com
  to:
    kind: Service
    name: myapp
  tls:
    termination: edge
    insecureEdgeTerminationPolicy: Redirect

Key option: insecureEdgeTerminationPolicy:

Passthrough Termination

Use when:

Limitations:

Example:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: myapp-passthrough
spec:
  host: secure.myapp.apps.example.com
  to:
    kind: Service
    name: myapp-https
  tls:
    termination: passthrough

Re-encrypt Termination

Use when:

Example:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: myapp-reencrypt
spec:
  host: myapp-secure.apps.example.com
  to:
    kind: Service
    name: myapp
  tls:
    termination: reencrypt
    destinationCACertificate: |-
      -----BEGIN CERTIFICATE-----
      ...
      -----END CERTIFICATE-----

The destinationCACertificate field is used by the router to verify the backend’s certificate.

Advanced Route Features

Beyond simple host-to-service mapping, Routes support several advanced routing features.

Path-Based Routing

Routes can optionally specify a spec.path, making them match only a subset of the URL:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: api-route
spec:
  host: myapp.apps.example.com
  path: /api
  to:
    kind: Service
    name: myapp-api

Multiple Routes can share the same host but different paths, each pointing to different Services. The router:

Wildcard Routes

Routes support wildcard hosts, such as *.example.com, enabling routing for multiple subdomains with a single Route.

Example:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: wildcard-route
spec:
  host: '*.apps.example.com'
  to:
    kind: Service
    name: shared-backend
  wildcardPolicy: Subdomain

Use cases:

Sticky Sessions (Session Affinity)

For stateful HTTP applications, you may require that requests from the same client are always routed to the same Pod.

Example annotations (actual keys may vary with router implementation/version):

metadata:
  annotations:
    haproxy.router.openshift.io/disable_session_affinity: "false"

Be aware:

Custom Headers and Timeouts

Routes can be annotated to control behaviors such as:

Examples:

metadata:
  annotations:
    haproxy.router.openshift.io/timeout: 5m
    haproxy.router.openshift.io/hsts_header: "max-age=31536000;includeSubDomains;preload"

Exact annotation keys depend on the router implementation (commonly HAProxy-based in OpenShift).

Route Sharding and Multiple Routers

In larger environments:

Typical reasons:

Kubernetes Ingress on OpenShift

While Routes are OpenShift-specific, Ingress is the Kubernetes standard API for HTTP(S) external access.

Basic Ingress Structure

An Ingress defines:

Example:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp-ingress
spec:
  rules:
  - host: myapp.apps.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: myapp
            port:
              number: 80
  tls:
  - hosts:
    - myapp.apps.example.com
    secretName: myapp-tls

On OpenShift:

Comparing Routes and Ingress

Key differences from a user perspective:

When to use which:

Ingress Controllers and OpenShift Routers

An IngressController in OpenShift is a cluster-scoped resource that defines how routers/ingress pods behave and where they run.

Example (simplified):

apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
  name: default
  namespace: openshift-ingress-operator
spec:
  domain: apps.example.com
  replicas: 2
  endpointPublishingStrategy:
    type: LoadBalancerService

Important aspects:

Routes and Ingress resources are bound to a given IngressController based on:

Practical Considerations and Patterns

Mapping DNS and Domains

In practice, to use Routes/Ingress:

  1. Cluster admin configures an IngressController with domain, e.g. apps.example.com.
  2. DNS is configured so that *.apps.example.com points to:
    • The load balancer in front of the routers, or
    • The router nodes (depending on the publishing strategy).
  3. As a developer, you create:
    • Routes or Ingress with hosts that are subdomains of apps.example.com.

No per-Route DNS record is usually needed due to wildcard DNS.

Choosing Hostnames

Guidelines:

Blue-Green and Canary with Routes

Routes can help implement deployment strategies:

Security and Compliance Considerations

Hands-On Checklist for Routes and Ingress

To solidify understanding, focus on being comfortable with:

These skills prepare you to build on top of OpenShift’s networking stack, integrating routes and ingress with security, scaling, and application deployment patterns described in other chapters.

Views: 13

Comments

Please login to add a comment.

Don't have an account? Register now!