I am working with microservices and netflix oss. I am using Eureka for service registry and discovery. I am trying out different options to understand behaviour of Eureka server. I still have some doubts with respect to below mentioned scenario.
I have couple of microservices, Service-A and Service-B. I also have two Eureka server instances viz. Eureka-1(port:8761) and Eureka-2(port:8762). I have registered both services with only Eureka-1. Also, service-A is invoking Service-B using eureka service instance name.
When I run Service-A, Service-B, Eureka-1 and Eureka-2 services, I am able to hit Service-A which internally hitting Service-B as expected. However, when I take Eureka-1 instance down and hit service-A, it still able to hit Service-B internally using eureka service instance name. My question is does Eureka-2 instance come to know about services registered with Eureka-1 instance. If yes, how and when does this communication happens between Eureka server instances?? Please help me understand this.
There is a good write up on the Netflix site (https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication) that explains how eureka peer to peer happens.
If you have both eureka-1 and eureka-2 pointing at each other (i.e. their eureka client definition in the yml files), then when you register to eureka-1, eureka-2 will get the list of available services from eureka-1.
So once paired, eureka-2 will have the same list as eureka-2 and discovery will work.
You should probably put your eureka-1 and 2 configuration in your question so we have more detail
Related
I have a couple of microservices that I want to register in Consul, so that they can find each other and communicate.
Everything runs on docker compose.
I am wondering how that would work if one of the two services has multiple replicas. How does Consul (or docker compose) deal with that? Is there some sort of internal load balancing or what?
Consul supports registering multiple instances/replicas of a service. When a consumer queries the Consul catalog, Consul will return information for each of the registered service instances.
If the consumer/client is querying Consul via DNS, the client's DNS resolver will ultimately be responsible for choosing the endpoint to connect to from the list of IP's in the DNS response.
If the client is querying Consul via the HTTP API (e.g., /v1/agent/health/service/:service), the client must implement its own logic to select an upstream instance from the list of instances returned in the API response.
See the query services section of the Register a Service with Consul Service Discovery tutorial for more info.
Context
I am deploying a set of services that are containerised using Docker into AWS. No matter which deployment solution is chosen (e.g. raw EC2/ECS/Elastic Beanstalk/Fargate) we will face the issue of "service discovery".
To name just a few of the options for service discovery that I've considered:
AWS Route 53 Service Registry
Kubernetes
Hashicorp Consul
Spring Cloud Netflix Eureka
Specifics Of My Stack
I am developing Java Spring Boot applications using Spring Cloud with the target deployment environment being AWS.
Given that my stack is Spring based, spring cloud eureka made sense to me while developing locally. It was easy to set up a single node, integrates well with the stack and ecosystem of choice and required very little set up.
Locally, we are using docker compose (not swarm) to deploy services - one of the containers deployed is a single node Eureka service discovery server.
However, when we progress outside of local development and into staging or production environment we are considering options like Kubernetes.
My Own Assessment Of Pros/Cons
AWS Route 53 Service Registry
Requires us to couple code specifically to AWS services. Not a problem per se, we are quite tied in anyway on other parts of the stack (SNS/SQS).
Makes running the stack locally slightly more difficult as it relies on Route 53, I suppose we could open up a certain hosted zone for local development.
AWS native, no managing service registries or extra "moving parts".
Spring Cloud Eureka
Downside is that thus requires us to deploy and manage a high availability service registry cluster and requires more resources. Another "moving part" to manage.
Advantages are that it fits into our stack well (spring ecosystem, spring boot, spring cloud, feign and zuul work well with this). Also can be run locally trivially.
I presume we need to configure the networks and registry zone to ensure that that clients publish their host address rather and docker container internal IP address. e.g. if service A is on host A and wants to talk to service B on host B, service B needs to advertise its EC2 address rather than some internal docker IP.
Questions
If we use Kubernetes for orchestration, are there any disadvantages to using something like Spring Cloud Eureka over the built in service discovery options described here https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services
Given Kube provides this, it seems suboptimal to then use eureka deployed using kube to perform discovery. I presume kube can make some optimisations that impact avaialbility and stability that might nit be possible using eureka. e.g kube would know when deploying a new service - eureka will have to rely on heartbeats/health checks and depending on how that is configured (e.g. frequency) this could result in stale records whereas i presume kube might not suffer from this for planned service shutdown/restarts. I guess it still does for unplanned failures such as a host failure or network partition.
Does anyone have any advice on this, do people use services like Kubernetes but use other mechanisms for service discovery rather than those provided by kube. Is there a good reason to do one or the other?
Possible Challenges I Anticipate
We could replace eureka, but relying on Kube to perform discovery will mean that we need to run kube locally to deploy whereas currently we have a simple tiny docker-compose file. Also, I'll have to look at how easy it'll be to ensure that ribbon, zuul and feign play nicely with this.
Currently we have ribbon configured with a eureka client so that service A can server to service B just as "service-b" for example and have ribbon resolve a healthy host via a eureka client. I guess we can configure ribbon to not use eureka and use an external Kube service name which will be resolved by Kube DNS at runtime...
Final Note
Thanks in advance for any contribution or advice. I know this might elicit a primarily opinion focused response. But I am hoping someone can provide objective guidance on when one solution might be preferable to another.
Service discovery is something you get out-of-the-box with Kubernetes. So having another external service in your platform will be another application to maintain, deploy and can be a point of failure. So I would stick with the the service discovery provided by Kubernetes.
I have a service which runs a couple of verticles. The main verticle configures the remaining verticles and is also responsible for registering the service with consul. However, my gRPC server cannot run on the same port as the main verticle. Does this mean I need to register each verticle as a separate service, or is there some way to use consul to advertise the correct port for my gRPC server?
It seems like tags are the way to go. I can't find the link to the github issue discussing single services with multiple ports, but that was the suggestion. Multiple ports is something being considered for a future API but there are obstacles such as the SRV entries to contend with before this is possible.
As part of the move from Eureka to consul (Spring Cloud), we are looking at replicating certain behaviours.
One of them is that if a service disconnected to Eureka after a significant will reconnect when it can see Eureka again.
I see that a service will retry to consul and eventually stop. Is there a way to replicate the same behaviour on a service to consul past the max retries/backoff?
Just trying to support expected behaviours
It's a known issue https://github.com/spring-cloud/spring-cloud-consul/issues/197. That functionality you describe is built into the eureka thick client and something similar would need to be built for spring-cloud-consul.
Like to know the difference between Service Registry and Discovery in Zookeeper in terms of Microsesrvices
This question is not specific to Zookeeper so these principles apply to every implementation (Eureka, Consul, Zookeeper, etc...)
Service registry is the registry where all services register themselves, giving a way to contact them (public API, IP, port).
Service Discovery is the action of retrieving a specific service for your need, basically asking the service registry to get an URL to call.