Bootstrap FreeKB - OpenShift - List Routes using the oc get routes command
OpenShift - List Routes using the oc get routes command

Updated:   |  OpenShift articles

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

A route or an ingress object will provide a URL such as hello-world.apps.openshift.example.com which is used to route a request onto a service, which is then routed onto a pod, and then to the container in the pod, and finally to the application running in the container.

 

Like this.

 

Here is an example of what could be returned by the oc get routes command.

TIP

The -A or --all-namespaces flag can be used to list the routes in every project / namespace.

The -n or --namespace flag can be used to list the routes in a certain project / namespace.

~]# oc get routes
NAME        HOST/PORT                                          PATH   SERVICES     PORT     TERMINATION          WILDCARD
my-route    my-route-my-project.apps.openshift.example.com            my-service   8080     reencrypt/Redirect   None

 

The oc describe route command can be used to show more information about a route. 

In this example, when a request is submitted to http:/my-route-my-project.apps.openshift.example.com:8080, the request will be forwarded onto the service named "my-service".

When a route is created, the format of the route URL is <route name>-<project/namespace>-<ingress domain>:<port>.

~]# oc describe route my-route

Name:                   my-route
Namespace:              my-project
Created:                7 days ago
Labels:                 app=my-app
                        route-type=default
                        velero.io/backup-name=ef0cd250-04c7-11eb-8fe1-67064a920610-shfm6
                        velero.io/restore-name=ef0cd250-04c7-11eb-8fe1-67064a920610-t9jf5
                        openshift.io/backup-registry-hostname=docker-registry.default.svc:5000
                        openshift.io/backup-server-version=1.11
                        openshift.io/restore-registry-hostname=image-registry.openshift-image-registry.svc:5000
                        openshift.io/restore-server-version=1.18
Requested Host:         my-route-my-project.apps.openshift.example.com
                          exposed on router default (host apps.openshift.example.com) 7 days ago
Path:                   <none>
TLS Termination:        reencrypt
Insecure Policy:        Redirect
Endpoint Port:          prometheus

Service:        my-service
Weight:         100 (100%)
Endpoints:      <error: endpoints "my-route" not found>

 

Or, the oc get routes command with the --output json​ or --output yaml option can be used.

~]$ oc get route my-route --output json
{
    "apiVersion": "route.openshift.io/v1",
    "kind": "Route",
    "metadata": {
        "annotations": {
            "openshift.io/host.generated": "true"
        },
        "creationTimestamp": "2022-07-28T01:44:51Z",
        "labels": {
            "app": "my-app",
            "app.kubernetes.io/component": "my-app",
            "app.kubernetes.io/instance": "my-app"
        },
        "name": "my-route",
        "namespace": "foo",
        "resourceVersion": "446042921",
        "uid": "769c8df4-9924-4d0e-a551-f465f1397a66"
    },
    "spec": {
        "host": "my-route-my-project.apps.openshift.example.com",
        "port": {
            "targetPort": "8080-tcp"
        },
        "to": {
            "kind": "Service",
            "name": "my-service",
            "weight": 100
        },
        "wildcardPolicy": "None"
    },
    "status": {}
}

 

The --output jsonpath option can be used to print the value of a specific JSON key.

~]$ oc get route my-route --output jsonpath={.spec.host}
my-route-my-project.apps.openshift.example.com

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


September 18 2023 by Frank King
very helpful...

Add a Comment


Please enter 70d242 in the box below so that we can be sure you are a human.