OpenShift - Assign an external IP address to a service using the oc patch service command

by
Jeremy Canfield |
Updated: July 03 2022
| OpenShift articles
There are a few different ways to route external requests to a pod / service.
- Using an OpenShift route (this is the most common)
- Using an ingress route
- Using a load balancer service
- Assigning an external IP address to a service
Let's say you have a service named hello-openshift which is used to route requests onto the hello-openshift pod. By default, the service will not have an external IP address assigned, which can be seen with the oc get services command.
~]$ oc get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-openshift ClusterIP 10.217.5.8 <none> 8080/TCP 7d
The oc describe pod command can be used to see that the hello-openshift pod is running on the work node that has IP address 10.17.168.6.
~]$ oc describe pod/hello-openshift
Name: hello-openshift
Namespace: foo
Priority: 0
Node: lab001-worker-hsjrp/10.17.168.6
The oc patch service command can be used to assign the service an external IP address.
~]$ oc patch service hello-openshift --patch '{"spec":{"externalIPs":["10.17.168.6"]}}'
service/hello-openshift patched
And now the oc get services command should show that the service has the external IP address. You can now try to access the service at http://10.17.168.6:8080.
~]$ oc get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-openshift ClusterIP 10.217.5.8 10.17.168.6 8080/TCP 7d
Did you find this article helpful?
If so, consider buying me a coffee over at