Multi-Cluster Kubernetes Service Discovery using Consul and Spring Cloud Consul

4/16/2020

Alright, so I have two bare metal Kubernetes clusters, with no cloud providers. I have microservices written in spring boot. Now I want to build a production grade service discovery mechanism for inter-service communication.

My basic intention is to support multi-cluster service to service communication. So a microservice-1 on cluster-1 should be able to call microservice-2 on cluster-2. Fair enough ?

In pursuit of this, I spent countless hours in researching. I explored Native Kubernetes Service Discovery, Istio, Eureka etc but none of these could really serve my purpose.

I am finally thinking to settle down on Hashicorp’s Consul and Spring Cloud Consul project.

With the help of Consul’s Service Syncing, I was able to register the Kubernetes services (of type NodePort) to Consul on one cluster. So for now my Kubernetes cluster-1 and consul server are on the same Linux machine.

I have enabled spring cloud consul in my spring boot services but disabled their registration to Consul because if I enable the registration, Kubernetes pods will get registered in Consul. I want the Kubernetes Services to get registered so that when a client asks Consul about a target service, Consul can return the host and nodePort of the target service. Host and nodePort will enable me to call services across the clusters.

I have two questions for the community :

  1. I want to deploy microservices on the second Kubernetes cluster and register them to the consul server of the first machine basically to keep all the service registry at one place. I don’t want to install another Consul server on the second cluster and moreover Consul-1 and Consul-2 will be mutually out of sync. So second installation is a no go. How can I solve this ?
  2. I want to load balance on the client side using Ribbon. I want to load balance between two Kubernetes services returned by Consul. How can I do that ?

Also, if you guys have any better suggestions for achieving what I want then please let me know.

Apologies for a long textual question.

-- ABhinav
consul
kubernetes
microservices
spring-boot
spring-cloud-consul

0 Answers