Bootstrap FreeKB - OpenShift - Exchanging messages between pods
OpenShift - Exchanging messages between pods

Updated:   |  OpenShift articles

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

By default, OpenShift allows pods in the same namespace to communicate with each other. Let's say you've deployed two hello-world pods in the same namespace.

~]# oc get pods
NAME                   READY   STATUS     RESTARTS  AGE
hello-world-1-9mzm2    1/1     Running    0         8d
hello-world-2-vmzmz    1/1     Running    0         8d

 

The oc describe command can be used to get the IP address and Port of the hello-world-2 pod.

~]$ oc describe pod hello-world-2-vmzmz
IP:           10.131.5.3
Containers:
  hello-world:
    Ports:          8080/TCP

 

The oc exec and curl command can be used to submit a request from the hello-world-1 pod to the hello-world-2 pod using the IP address and Port of the hello-world-2 pod.

~]# oc exec pod/hello-world-1-9mzm2 -- curl 10.131.5.3:8080 -v
* Connected to 10.131.5.3 (10.131.5.3) port 8080 (#0)
< HTTP/1.1 200 
Hello World

 


SERVICE

Let's say you use the oc expose pod command to create a service that will be used to route requests onto the hello-world-2 pod.

~]$ oc expose pod hello-world-2-vmzmz --name hello-world-2-service
service/hello-world-2-service exposed

 

The oc get services command should show the service has been created.

~]$ oc get services
NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
hello-world-2-service   ClusterIP   172.30.179.246   <none>        8080/TCP   3m24s

 

The oc exec and nslookup command can be used to see that the pod is able to resolve the service name to the CLUSTER-IP address of the service. If the pod does not have the nslookup command install, you may need to update to deployment to run as root and then use the dnf install or yum install command to install the bind-utils package.

~]$ oc exec pod/hello-world-1-9mzm2 -- nslookup hello-world-2-service
Server:         172.30.0.10
Address:        172.30.0.10#53

Name:   hello-world-2-service.my-project.svc.cluster.local
Address: 172.30.179.246

 

The oc exec and curl command can be used to submit a request from the hello-world-1 pod to the hello-world-2 service using the name of the service instead of the IP address of the pod.

~]# oc exec pod/hello-world-1-9mzm2 -- curl hello-world-2-service:8080 -v
* Connected to hello-world-2-service (172.30.179.246) port 8080 (#0)
> Host: hello-world-2-service:8080
< HTTP/1.1 200
Hello World

 

This works because when you expose the service, the service know that requests on port 8080 go to the pod with IP address 10.131.5.3 (in this example), which is the hello-world-2 pod.

~]$ oc describe service hello-world-2-service
Endpoints:         10.131.5.3:8080

 


INGRESS | ROUTE

An OpenShift route or an Ingress route will provide a URL such as http://my-route-my-project.apps.openshift.example.com:8080 which is used to route a request onto a service, which is then routed onto a pod, and then to the container in the pod, and finally to the application running in the container.

 

The oc expose service command can be used to create an insecured route, whereas the oc create route command is used to create a secured (SSL) route. In this example, the oc expose service command is used to route requests onto hello-world-2-service.

~]$ oc expose service hello-world-2-service --name hello-world-2-route --port 8080 --labels route-type=default
route.route.openshift.io/hello-world-2-service exposed

 

The oc get routes command can be used to see that http://hello-world-2-route-my-project.apps.openshift.example.com is the URL to submit a request to the route > service > pod.

~]# oc get routes
NAME                     HOST/PORT                                                     PATH   SERVICES                 PORT     TERMINATION WILDCARD
hello-world-2-route      hello-world-2-service-my-project.apps.openshift.example.com          hello-world-2-service    8080-tcp             None

 

The oc exec and nslookup command can be used to see that the pod is able to resolve the route name to the IP address of the route.

~]$ oc exec pod/hello-world-1-9mzm2 -- nslookup hello-world-2-route-my-project.apps.openshift.example.com
Name:   hello-world-2-route-my-project.apps.openshift.example.com
Address: 10.84.188.68

 

Similarly, the nslookup command outside of the pod, on the command line, can be used to resolve the route name to the IP address of the route.

~]$ nslookup hello-world-2-route-my-project.apps.openshift.example.com
Name:   hello-world-2-route-my-project.apps.openshift.example.com
Address: 10.84.188.68

 

The oc exec and ping command can be used to determine if you are able to exchange ICMP echo request packets.

~]$ oc exec pod/hello-world-1-9mzm2 -- ping -c1 hello-world-2-route-my-project.apps.openshift.example.com
PING hello-world-2-route-my-project.apps.openshift.example.com (10.84.188.68) 56(84) bytes of data.
64 bytes from apps-virtual-ip1.openshift.example.com (10.84.188.68): icmp_seq=1 ttl=63 time=0.933 ms
1 packet transmitted, 1 received, 0% packet loss, time 0.933ms

 

And curl can be used to submit a request to the route, which should forward the request onto the service, and then onto the pod.

oc exec pod/hello-world-1-9mzm2 -- curl -v http://hello-world-2-route.my-project.apps.openshift.example.com/

 




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 44ab59 in the box below so that we can be sure you are a human.