How to connect microservice with NATS docker image inside kubernetes cluster

6/16/2020

I was trying to connect 2 microservices via nats which worked out pretty well in local environment, i used docker image of NATS and used its pub-sub model. But now my task is to connect those 2 microservices inside kubernetes cluster. I made docker images of those microservices but can't figure out how to connect them via the container image of NATS.

docker image of NATS - https://hub.docker.com/_/nats

-- Kanishk Khandelwal
kubernetes
microservices
nats.io

1 Answer

6/16/2020

To communicate two pods in kubernetes you have to expose them using a service. If you dont want to expose them to outside the cluster you can use ClusterIP as service type.

You can see here all the documentation about services in kubernetes.

https://kubernetes.io/docs/concepts/services-networking/service/

-- JArgente
Source: StackOverflow