4

In OpenShift Container Platform v3.11 I can able to see the service hostname from the web console interface by inspecting the service.

In the web console if going to Applications > Services > service-name > Details.

You see the following info:

Selectors: app=nexus3, deploymentconfig=nexus3
Type: ClusterIP
IP: 172.30.154.6
Hostname: nexus3.xm-nexus.svc
Session affinity: None

Is there a way to see the service hostname from the CLI using the oc tool? I haven't been able to find it from reading the docs or online.

Example Hostname: nexus3.xm-nexus.svc

If you issue a oc get svc you will see the following but not the hostname.

NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
nexus        ClusterIP   172.30.186.244   <none>        3000/TCP   2h
alexdotsh
  • 166
  • 1
  • 10

3 Answers3

5

Not directly. The hostname doesn't exist on the service object itself so you won't see it via the cli. However it is just a concatenation of (service-name).(service-namespace).svc. See docs on DNS for services

You could template it out via the cli if desired.

oc get svc nexus -o go-template --template='{{.metadata.name}}.{{.metadata.namespace}}.svc{{println}}'

PhilipGough
  • 1,709
  • 1
  • 13
  • 18
-2

Use oc describe service -n

e.g. oc describe service nexus3 -n

Services are provisioned labels like DNS.

-2

I think the simplest way is

oc get routes

And get the hostname that you need to access by url

NAME          HOST/PORT                                     PATH      SERVICES      PORT      TERMINATION   WILDCARD
demowildfly   demowildfly-swarmdemo2.192.168.42.87.nip.io             demowildfly   8080                    None
Fernando
  • 7
  • 3
  • @AlexMirkhaydarov , look at how to watch the hostname and use the **oc get svc** command, **but he still ask about the hostname** , so, my solution give another point of view and shows the host. – Fernando Jul 28 '21 at 11:50