In the ‘CLI Quick Start’ section, there is a sentence describing the service discovery :
“One of the major use cases for Consul is service discovery. Consul provides a DNS interface that downstream services can use to find the IP addresses of their upstream dependencies.”
It said that it would help the downstream find the IP addresses, so why don’t we use the key/value? Which is easier to configure. What is the biggest difference between them?
Service Discovery = DNS … everything knows how to do DNS lookups. Does not need authentication.
KV … requires either a consul binary or knowing API to access. May or may not need authentication.
@aram’s answer is correct. Its much easier for applications to resolve services in Consul if they are using Consul for DNS resolution.
KV does require the application to be Consul-aware and have the appropriate tokens to access the KV paths.
Using DNS implies that your services have been registered to Consul. By registering services, you can also associate health checks with those services, and ensure that Consul only returns healthy instances in response to service discovery requests.
Check out the following tutorial for an example of this.
Health checking is not available if you are storing IP addresses/hostnames in the KV store, and relying on those values for service discovery in your applications.