Skip to content

Routes

OpenShift Only

Routes are OpenShift objects that expose a Service at a hostname, so clients outside the cluster can reach it. The cluster's router (HAProxy-based) receives the traffic on ports 80 and 443 and forwards it to the Service's pods.

  • A Route can be unsecured (HTTP) or secured with TLS using edge, passthrough or reencrypt termination.
  • If you don't set a hostname, OpenShift generates one: <route-name>-<project>.<apps-domain>.
  • oc expose service creates a Route that takes its name from the Service, unless you pass --name.
  • Routes can split traffic between several Services by weight, which is useful for blue-green and canary releases.

For portable manifests you can also use a Kubernetes Ingress, which OpenShift converts into a Route.

Resources

References

Route
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: frontend
spec:
  to:
    kind: Service
    name: frontend
  port:
    targetPort: 8080
Secured (edge) Route that redirects HTTP to HTTPS
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: frontend-secure
spec:
  to:
    kind: Service
    name: frontend
  port:
    targetPort: 8080
  tls:
    termination: edge
    insecureEdgeTerminationPolicy: Redirect
Canary: send 10% of traffic to a new version
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: frontend-canary
spec:
  to:
    kind: Service
    name: frontend
    weight: 90
  alternateBackends:
    - kind: Service
      name: frontend-v2
      weight: 10
  port:
    targetPort: 8080

Commands

Create Route from YAML
oc apply -f route.yaml
Create a Route for a Service
oc expose service frontend
Create an edge-terminated TLS Route
oc create route edge frontend-secure --service=frontend --insecure-policy=Redirect
Get the Route's URL
oc get route frontend -o jsonpath='{.spec.host}{"\n"}'
Get Route
oc get route
Describe Route
oc describe route <route_name>
Get Route YAML
oc get route <route_name> -o yaml