I am trying to expose my two springboot applications to the external network which are on AWS storage and I'm getting my head blown because I can't make one of them reach another one. The first application, let's call it A, it returns the rest page with a number:123, the second one is returning the name of host specified in deployment file of first application: let's say hostname: datahost
. It has a method /getnumber
which returns this number when put into web browser. It's working on 8080 port.
The point is that the second application has a return statement of "http://datahost:8080/getnumber", which should be returning the result of first application /getnumber
result. Unfortunately the return statement is:
There was an unexpected error (type=Internal Server Error, status=500). I/O error on GET request for "http://datahost:8080/getnumber": datahost; nested exception is java.net.UnknownHostException: datahost
Can u guys explain or give a tip how to make those applications be visible for eachother? They are both in two another pods and in the same node. Furthermore if I use it on localhost on a computer and forward it to localhost:8080/getnumber, then it works.
In order to make two PODs connect to each other, you need to create a Service
for your pods.
As a simple example, you can run a command similar to this one:
kubectl -n <your namespace> expose pod <your pod name> --port 8080
You'll end up having an object of type Service
created and you will be able to reach your pod by using the service name as the hostname.
Again, this is just an example and you probably want to expose your deployment
rather than your pod
More details here: https://kubernetes.io/docs/concepts/services-networking/service/