Service discovery tools let microservices register themselves and locate other services dynamically at runtime instead of relying on hard-coded network addresses; Eureka and Consul are two commonly implemented options in the Spring Boot ecosystem.
Key Points: • Eureka requires adding the spring-cloud-starter-netflix-eureka-client dependency and configuring eureka.client.service-url.defaultZone to point to the Eureka server so the service can register itself on startup. • Consul, from HashiCorp, is configured similarly via spring-cloud-starter-consul-discovery and typically runs a Consul agent alongside each application instance or node. • In a Kubernetes cluster, Consul agents are often deployed as a DaemonSet so every node has a local agent handling registration and health checks. • Kubernetes itself provides built-in service discovery via DNS and Services/Endpoints objects, which can reduce or eliminate the need for Eureka when running natively on K8s. • Both tools require health-check configuration so unhealthy instances are removed from the registry automatically.
Example: A Spring Boot service deployed to Kubernetes with Consul would run a Consul agent as a sidecar or node-level DaemonSet, register itself with a health-check endpoint, and other services would query Consul's catalog API to resolve the current healthy instances.
Code Example:
# application.yml (Eureka client)
eureka:
client:
service-url:
defaultZone: http://eureka-server:8761/eureka/
instance:
prefer-ip-address: trueInterview Tip: A concise interview answer is:
"I've implemented both Eureka and Consul for service discovery. Eureka just needs the client dependency and a defaultZone pointing at the Eureka server, while Consul additionally requires an agent running per node, which in Kubernetes is usually deployed as a DaemonSet alongside health-check configuration for both."