Spring boot eureka - remove dead services - netflix-eureka

I am researching about Eureka for services discovery and I found out that if I kill a process, eureka displays it as "DOWN". Will it clean it and remove it on it's own someday?
The scenario is this: Lets say I am working with amazon AWS. I want to upload a new version this way: prepare X new machines and kill the old ones.
The new machines will register to eureka on startup, but how will the old machines be unregistered from Eureka?
I use java and spring-cloud.
Thanks,
Ido

Not sure if this will help you but you can try this.
Eureka server application.yml
eureka:
server:
enableSelfPreservation: false
Service application.yml
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
Read this for info:- https://github.com/ExampleDriven/spring-cloud-eureka-example

Related

Eureka unresponsive on changing networks

I am using netflix-eureka as the discovery service in my spring-cloud application.
Currently facing a problem where if I have all microservices registered to eureka server, they work perfectly fine. However, If i change networks (Get home from office or vice versa) the services become unresponsive unless I restart all the microservices.
I have also noticed that with office net the services are registered against their respective IP addresses, while at home they seem to get registered against the host name.
I already have the 'prefer-ip-address' config set to true.
The following is the configuration in each microservice:
eureka:
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: http://localhost:8761/eureka
instance:
prefer-ip-address: true
hostname: localhost
Any idea why changing networks would cause this issue or why the services are registered against host name despite 'prefer-ip-address' set to true?

Eureka and Consul

I am implementing a service discovery and I evaluating two options: Eureka and Consul.
Help me decide! I am leaning towards Eureka, but I need to clear a main tech problem. My infrastructure is based on openshift. I can have multiple containers running Eureka Servers behind a load balancer. As far as I know each server needs to communicate with each other. Also, Eureka is mainly used with AWS...
(newbie) Question:
1) How can I configure each Eureka Server to communicate with each other? I have a single (load balanced) URL. My fear is that each server potentially may become desynchronized.
2) Am i missing something?
You're right, each of the Eureka Server must communicate with each other. You can also play with regions depending on your approach.
To make it work (without zones), you must configure the property:
eureka.client.service-url.defaultZone: http://1st-eureka-server-ip-or-hostname:port/eureka/,http://2nd-eureka-server-hostname:porta/eureka/
The configuration above accepts a comma-delimited set of IP/hostname of all the Eureka Servers.
If you want to have a multi-zone configuration, I recommend you to read this blog post.
To Configure each Eureka Server to communicate with each other try this way to make a diffrent diffrent zone in resource in folder.
application-zone1.yml
server.port: 8001
eureka:
instance:
hostname: localhost
metadataMap.zone: zone1
application-zone2.yml
server.port: 8002
eureka:
instance:
hostname: 127.0.0.1
metadataMap.zone: zone2
application.yml
client:
register-with-eureka: false
fetch-registry: false
region: region-1
service-url:
zone1: http://localhost:8001/eureka/
zone2: http://127.0.0.1:800/eureka/
availability-zones:
region-1: zone1,zone2
spring.profiles.active: zone1
Follow this tutorial

Register micro-services using spring-eureka from more than 1 server

I have a set of micro-services which need to communicate to each other.
The total number of micro-services does not fit to single physical server so I need to spread them out among 2 different servers.
My idea (do not know if correct) is to have spring-eureka instance per server to which all services from this particular server register. So:
Services (A,B) register to Eureka on Server 1.
Services (C,D) register to Eureka on Server 2.
After that eureka instances will exchange their knowledge (Peer Awareness).
The questions are:
Does described idea is correct approach? Or rather there should exist just single Eureka instance on single server to which all services from both servers will register (i.e. Eureka exists only on Server1)?
If described idea is correct then as I understand ports 8761 should be opened on Server1 and Server2 to allow communication between "Eurekas"? And the configuration should be as following:
Eureka on Server 1:
eureka.client.serviceUrl.defaultZone: http[s]://server2address:8761/eureka/
Eureka on Server 2:
eureka.client.serviceUrl.defaultZone: http[s]://server1address:8761/eureka/
1) normally you would have a server for each service (A,B,C,D eureka1 and eureka2)
2) eureka.client.serviceUrl.defaultZone is a comma separated list so it is more like "eureka.client.serviceUrl.defaultZone: http[s]://server1address:8761/eureka/,http[s]://server2address:8761/eureka/" for each service
Hope that helps, cheers

Cannot prevent my service from registering with Eureka

I have a Spring Boot application with the following config:
eureka:
client:
enabled: true
registerWithEureka: false
serviceUrl:
defaultZone: http://somehost:9999/eureka/
registration:
enabled: false
My service makes use of Eureka to discover external services, but I don't want it to register with Eureka. Despite the above config I still see the following in my logs, which is odd:
DiscoveryClient - Not registering with Eureka server per configuration
...
EurekaServiceRegistry - Registering application foo with eureka with status UP
The first log line makes sense - it's what I want. However, the second log line doesn't make sense given the config. Am I missing a setting?
You didn't missing anything and your configuration is right. The second log just says that what happened in your local process.
The all periodic tasks that are related to actual registration process (ex heartbeat, instance info replication) with Eureka server are not scheduled by your configuration. So registration with Eureka server will not happen.

how does zuul work without eureka and ribbon for dynamic destination from kubernetes

I am a beginner of using Zuul. I would like to create a http proxy for dynamic destination (ip address) from kubernetes. I checked Can Zuul Edge Server be used without Eureka / Ribbon which is helpful, but I don't want to specify lists-of-servers.
What I have now is a simpleRouteFilter extends ZuulFilter based on spring-boot. In the filter, it will change the destination ip address according to what I get from kubernetes. And I also turn off the eureka stuff by using ribbon.eureka.enabled=false.
The problem is that it looks good in the local environment, but after I deploy the project into kubernetes, it will show Load balancer does not have available server for client: sample-all-services, but it indeed works. The reason why I put a sample-all-service (service id) there is that when I remove zuul config in the properties, the zuul function doesn't work properly. And I know that I didn't put any server for that id because it's dynamic.
Question:
(1) Is Zuul fit in my scenario?
(2) if yes, how to tune Zuul confguration to accept all the http requests without showing load balancer not available warn.
(3) Is that something related to the kubernetes?
The yaml file is:
zuul:
routes:
sample-all-services:
path: /**
server:
port: 8080
ribbon:
eureka:
enabled: false
sample-all-services:
ribbon:
ReadTimeout: 15000
Thanks.