Summarizing consul lookup in k8s environment with services + replicas?

Hi,

So I have the same k8s service running in say a 100 replicas in a replicaSet. And from each replica, I register with consul that “I am service foobar”, but each replica registers with its own ID - and when that replica loses the service it deregisters with that ID, so the service is still available as far as consul is concerned. But now if we do a consul service lookup, I will get a response back with a 100 entries !

Since its in a kubernetes environment, I just need to know if there is at least one replica offering the service, and kubernetes will do the load balancing to one of the available replicas. So is there a way by which I can tell consul that “service foobar lookup just needs ONE registration sent back, dont send all the 100 back” ?

Rgds,
Gopa.

Hi Gopa, what API calls are you using?

@lkysow I am using the dns SRV lookup … so in dns lookup I will end up getting 100 seperate IP addresses which is understandable I guess since I registered from 100 replicas seperately with independent IDs. Is there some other API which will get me some kind of a summary/“first entry” or something of that sort, if so I can change my dns lookup to use that instead

For the DNS API, I don’t think so. For the HTTP API you could use Catalog - HTTP API | Consul by HashiCorp and then cut it down to a smaller number yourself?

@lkysow the issue is that I dont want a lot of latency whenever I make these consul lookups - so if I have a like a thousand entries in the consul lookup result, that will be just additional latency incurred for the lookup which I want to avoid. I was hoping there will be an API that just says “get me just one entry amongst all the entries”