Spring boot app cannot connect to RabbitMQ on kubernetes Cluster

11/12/2019

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!

-- Adam
kubernetes
rabbitmq
spring-boot
spring-mvc

2 Answers

11/12/2019

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

-- Cristiano Almeida
Source: StackOverflow

11/12/2019

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.

-- Rodrigo Loza
Source: StackOverflow