
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> 12345/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> 12345/TCP 114d
The oc describe service command can be used to show the details of the service.
~]$ oc describe service myService001 --namespace my_project
Name: myService001
Namespace: my_project
Labels: <none>
Annotations: <none>
Selector: app=my-app
Type: ClusterIP
IP: 172.30.166.121
Port: http 12345/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": "http",
"port": 12345,
"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