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

There are a few different ways to route external requests to a pod / 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 Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





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