Spring boot application registers same instance, multipe times in consul cluster

712 views Asked by At

I am trying to register a spring boot app to a consul cluster.

  1. I have 3 node consul cluster 1 master 2 agents.
  2. I have a load-balancer in front of 2 consul agents, so that it is HA.
  3. In my application.yml. I ask the services to join via load-balancer
spring
  cloud:
    consul:
      enabled: true
      port: loadbalancer_port
      host: http://loadbalancer
      discovery:
        instance-id: ${info.app.environment}:${spring.application.name}
        tags:
          - ${spring.profiles.active}
  1. Now, when my service restarts it is creating a duplicate entry in consul.

  2. I figured that, because it is being registered in 2 different agents.

Does this mean, I cant have HA consul with loadbalancer ? or should I ask the services to register to particular agents with out load-balancer?

Please help!!

1

There are 1 answers

4
Blake Covarrubias On

Consul is designed to have a Consul client agent deployed on each server in your data center (see Consul Reference Architecture). Instead of registering services centrally, services running on a machine are registered with the local/co-located Consul agent. The agents then submit the list of services registered against them to the Consul servers, which then aggregates this info from each agent to form the service catalog. The catalog maintains the high-level view of the cluster, including which services are available, which nodes run those services, health information, etc.

TLDR; Remove the load balancer and register the services directly with the agents in order to avoid this issue where service registrations are duplicated across hosts.