Reputation: 379
I have a couple of microservices, deployed through S2I, on an openshift cluster. Each of them are exposed by service and route. The first microservice needs to communicate with the REST API of the other one (on another pod) through http. When I deploy the first microservice, I pass an environment variable MICROSERVICE_2_SERVICE_HOST with the value 'http://microservice-2' ('microservice-2' is the name of the generated openshift service of microservice 2, of type ClusterIP.. both generated services are of type ClusterIP)
Within the first microservice, I used the environment variable MICROSERVICE_2_SERVICE_HOST to build the URL of the REST API. The problem is that instead of getting 'http://172.30.245.8:8080/...' as one could expect in kubernetes, I'm getting 'tcp://172.30.245.8:8080/...' and the REST client cannot build the URL: java.net.MalformedURLException: unknown protocol: tcp
When I check the environment variables within the container of the microservice 1 I see:
MICROSERVICE_2_PORT=tcp://172.30.245.8:8080 MICROSERVICE_2_PORT_8080_TCP=tcp://172.30.245.8:8080 MICROSERVICE_2_PORT_8080_TCP_ADDR=172.30.245.8 MICROSERVICE_2_PORT_8080_TCP_PORT=8080 MICROSERVICE_2_PORT_8080_TCP_PROTO=tcp ...
I have tried changing the services to NodePort but I get the same result. I know I could use the IP:port values inside the string but I'd like to know why and how openshift works
Upvotes: 0
Views: 181
Reputation: 3226
This is inlined with the expected behaviour. I suppose you could use MICROSERVICE_2_SERVICE_PORT
and MICROSERVICE_2_SERVICE_HOST
to achieve the url composition.
Upvotes: 0