Bootstrap FreeKB - OpenShift - List Services using the oc get services command
OpenShift - List Services using the oc get services command

Updated:   |  OpenShift articles

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

There are different types of services, such as ClusterIP, NodePort and LoadBalancer. A service is used to forward requests onto one or more pods.

 

  • The ClusterIP service is only accessible within the OpenShift cluster
  • The NodePort service is accessible within your network
  • The LoadBalancer makes the service accessible externally, over the internet.

 

The oc get services command can be used to list the services in the currently selected project / namespace.

TIP

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

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

~]# oc get services
NAME               TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
myService001       ClusterIP      172.30.164.121   <none>        27017/TCP       114d
myService002       LoadBalancer   172.30.166.121   <pending>     8443:30444/TCP  114d

 

The oc get service command followed by the name of a service can be used to display an individual service.

~]# oc get service myService001
NAME               TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
myService001       ClusterIP   172.30.164.121   <none>        27017/TCP   114d

 

The oc describe service command can be used to show the details of the service.

~]$ oc describe service myService001
Name:              myService001
Namespace:         default
Labels:            app=my-app
Annotations:       <none>
Selector:          deployment=my-app
Type:              LoadBalancer
IP:                172.30.166.121
Port:              8080-tcp  8080/TCP
TargetPort:        8080/TCP
Endpoints:         10.131.5.3:8080
Session Affinity:  None
Events:            <none>

 

Or, the oc get services command with the --output json‚Äč or --output yaml option can be used.

~]$ oc get services my-service --output json
{
    "apiVersion": "v1",
    "kind": "Service",
    "metadata": {
        "annotations": {
            "openshift.io/generated-by": "OpenShiftNewApp"
        },
        "creationTimestamp": "2022-06-01T01:31:51Z",
        "labels": {
            "app": "my-service",
            "app.kubernetes.io/component": "my-service",
            "app.kubernetes.io/instance": "my-service"
        },
        "name": "my-service",
        "namespace": "foo",
        "resourceVersion": "422167682",
        "uid": "b658b5dc-00a0-46d5-bb4e-0b3a7f175812"
    },
    "spec": {
        "clusterIP": "172.30.179.246",
        "clusterIPs": [
            "172.30.179.246"
        ],
        "externalIPs": [
            "10.84.188.68"
        ],
        "ipFamilies": [
            "IPv4"
        ],
        "ipFamilyPolicy": "SingleStack",
        "ports": [
            {
                "name": "8080-tcp",
                "port": 8080,
                "protocol": "TCP",
                "targetPort": 8080
            },
            {
                "name": "8443-tcp",
                "port": 8443,
                "protocol": "TCP",
                "targetPort": 8443
            },
            {
                "name": "8778-tcp",
                "port": 8778,
                "protocol": "TCP",
                "targetPort": 8778
            }
        ],
        "selector": {
            "deployment": "my-app"
        },
        "sessionAffinity": "None",
        "type": "ClusterIP"
    },
    "status": {
        "loadBalancer": {}
    }
}

 

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

~]$ oc get services my-service --output jsonpath={.spec.clusterIP}
172.30.179.246

 




Did you find this article helpful?

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



Comments


Add a Comment


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