Connect to Consul server running openshift to consul client running on localhost - spring-boot

When I run consul on my local machine and spring boot client with following properties in bootstrap.properties, I can see that it connects, discovers services and able to connect from one service to other using service discovery.
Bootstrap.properties:
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.instance-id=consul-service2
spring.application.name=consul-service2
server.port=8083
But now, I installed consul on openshift provided route to it. I can browse to consul UI and see that consul service has registered itself. But when I try to connect client running on localhost to consul running on openshift i get error.
com.ecwid.consul.transport.TransportException: org.apache.http.conn.ConnectTimeoutException: Connect to consul-uservices-template.f-az.uk.paas.intranet.db.com:8500 [consul-uservices-template.hju-azh.uk.paas.intranet.sdf.com/10.248.36.85] failed: connect timed out
at com.ecwid.consul.transport.AbstractHttpTransport.executeRequest(AbstractHttpTransport.java:77) ~[consul-api-1.4.1.jar:na]
at com.ecwid.consul.transport.AbstractHttpTransport.makePutRequest(AbstractHttpTransport.java:41) ~[consul-api-1.4.1.jar:na]
at com.ecwid.consul.v1.ConsulRawClient.makePutRequest(ConsulRawClient.java:135) ~[consul-api-1.4.1.jar:na]
at com.ecwid.consul.v1.agent.AgentConsulClient.agentServiceRegister(AgentConsulClient.java:273) ~[consul-api-1.4.1.jar:na]
at com.ecwid.consul.v1.ConsulClient.agentServiceRegister(ConsulClient.java:309) ~[consul-api-1.4.1.jar:na]
My bootstrap.properties:
spring.cloud.consul.host=consul-uservices-template.hju-azh.uk.paas.intranet.sdf.com
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.instance-id consul-service2
spring.application.name=consul-service2
server.port=8083
What i am doing is providing route path as host, am I wrong here ? I can see that it tries to connect to consul-uservices-template.hju-azh.uk.paas.intranet.sdf.com:8500 and it times out. I get 404 even on browser when i try to hit this url. It should not be accessing with port number. How can i do that ?

It should not be accessing with port number.
As the route is provided via OpenShift (and you can access it the web UI too), I assume it is accessible through port 80.
If that is the case, you can specify spring boot to access consul via port 80 by change the following properties
spring.cloud.consul.port=80

Related

Not able to access Springboot deployed at GCP compute instance at port 8080

I have a springboot app running at port 8080 at one of the GCP instance. I have turned on the firewall rules to allow traffic to port 8080. But still when I try to access the deployed port [ http://external-IP:8080/myservice ] I am not able to. From browser I get "This site can be reached" and from postman I get the error Error: connect ECONNREFUSED :8080
I am not sure if there are any specific firewall rules or anything that I need to set.

Tcp client not connecting to server when using istio

I created two sample application(tcp-server and tcp-client) for checking TCP connection in istio environment. Used the below link to create server and client in g0
https://www.linode.com/docs/guides/developing-udp-and-tcp-clients-and-servers-in-go/
Deployed the application in kubernetes cluster and tested without istio, it is working fine.
But after installing istio(demo configuration, followed this url to install istio: https://istio.io/latest/docs/setup/getting-started/),
and redeploying the apps to fill with envoy-proxy, the client is not connecting to server
Also using below command makes the server connect success
sh -c "echo world | nc 10.244.1.29 1234" is
What am I doing wrong?
Posting the solution I found.
Issue: I was trying to connect to server using ip address and nodePort, which some how not working in istio environment
Solution: From Client instead of providing ip address and nodePort of server node, give service name and container port of server app.
Extra Info: For using client from outside cluster, create gateway and virtual service for server. In your external client provide nodePort and ip address of istio-ingress pod as server destination

Connection has timed out when trying to access spring boot app from another machine

I'm trying to deploy a spring boot app which will be usable in a LAN. I'm running the command mvn spring-boot:run, the application is launched perfectly, i can access it via localhost but not via other machines : The page loads until the error : The connection has timed out appears .
ANy recommendations ?
It is not accessible because the port in which your application is running is not exposed to the other machines. You can open firewall port to access it across the network.
The best approach is to setup either Apache httpd or nginx as fron't server to server your application on regular ports(80 and 443).

Spring boot app cannot connect to RabbitMQ on kubernetes Cluster

I deployed a RabbitMQ server on my kubernetes cluster and i am able to access the management UI from the browser. But my spring boot app cannot connect to port 5672 and i get connection refused error. The same code works , if i replace my application.yml properties from kuberntes host to localhost and run a docker image on my machine.I am not sure what i am doing wrong?
Has anyone tried this kind of setup.
Please help. Thanks!
Let's say the dns is named rabbitmq. If you want to reach it, then you have to make sure that rabbitmq's deployment has a service attached with the correct ports for exposure. So you would target http://rabbitmq:5672.
To make sure this or something alike exists you can debug k8s services. Run kubectl get services | grep rabbitmq to make sure the service exists. If it does, then get the service yaml by running 'kubectl get service rabbitmq-service-name -o yaml'. Finally, check spec.ports[] for the ports that allow you to connect to the pod. Search for '5672' in spec.ports[].port for amqp. In some cases, the port might have been changed. This means spec.ports[].port might be 3030 for instance, but spec.ports[].targetPort be 5672.
Do you are exposing TCP port of rabbitMQ to outside of cluster?
Maybe only management port has exposed.
If you can connect to management UI, but not on port 5672, maybe indicate that your 5672 port is not exposed outside of cluster.
Obs: if I not understand correctly your question, please let me know.
Good luck

Which URL to use for Websocket server on an EC2 instance behind ELB

I am running a spring boot application on an EC2 instance behind an ELB. The application has a chatroom using websocket and both the client code(JS) as well as websocket server code(Spring) are running on the EC2.
When running the application on my own computer I was able to use localhost/5000 on the JS code to connect to the websocket server. I changed the websocket URL to the ip address of the EC2 instance with the 5000 port after. (ws://...:5000) However, I am getting this error
Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
at joined (eval at xhr.onload
which then turns into this
failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
is this the right URL to be using? (The IP address of the ec2 instance)
Worked after getting rid of the 5000 port after ec2 ip address.

Resources