Spring boot Eureka in docker swarm registering wrong internal docker ip's - spring-boot

Docker nodes are registering with inter ip's in springboot-eureka
My conf is as follows
1. Spring-boot eureka deployed to swarm (1 node)
2. Created spring-boot client containers (2nodes) and registering with eureka
The above containers are deployed as separate deployments, and the client conf is as follows
eureka:
instance:
prefer-ip-address: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://eureka-server-address/eureka/
healthcheck:
enabled: true
Spring:
cloud:
inetutils:
ignored-interfaces:
- eth0
- eth1
- eth2
- eth3
- lo
the ip's come as 172.1.0.1 instead of real-external ip's. and docker containers fail to connect each other with the real ip's.
docker-compose
network_mode: bridge

Update:- The swarm functions in a different way we think it would.
1. The ip's are docker's internal network distributions which is what we know
2. The entire swarm itself is not a bignetwork to work internally (new lesson)
3. We need to create a new network inside swarm for the containers to talk to each other (known + new lesson ..yes got confused)
For people who are searching for an answer, Please research for docker swarm networking options and create 2 networks 1 for internal and 1 for external traffic and assign them to the containers in your docker-compose). I was able to get it work for my POC but it tend to be hard for going to do in the enterprise scale.

Related

Spring boot application registers same instance, multipe times in consul cluster

I am trying to register a spring boot app to a consul cluster.
I have 3 node consul cluster 1 master 2 agents.
I have a load-balancer in front of 2 consul agents, so that it is HA.
In my application.yml. I ask the services to join via load-balancer
spring
cloud:
consul:
enabled: true
port: loadbalancer_port
host: http://loadbalancer
discovery:
instance-id: ${info.app.environment}:${spring.application.name}
tags:
- ${spring.profiles.active}
Now, when my service restarts it is creating a duplicate entry in consul.
I figured that, because it is being registered in 2 different agents.
Does this mean, I cant have HA consul with loadbalancer ? or should I ask the services to register to particular agents with out load-balancer?
Please help!!
Consul is designed to have a Consul client agent deployed on each server in your data center (see Consul Reference Architecture). Instead of registering services centrally, services running on a machine are registered with the local/co-located Consul agent. The agents then submit the list of services registered against them to the Consul servers, which then aggregates this info from each agent to form the service catalog. The catalog maintains the high-level view of the cluster, including which services are available, which nodes run those services, health information, etc.
TLDR; Remove the load balancer and register the services directly with the agents in order to avoid this issue where service registrations are duplicated across hosts.

What is the use of "wait-time-in-ms-when-sync-empty" in Spring Eureka Server?

I was going through a tutorial and I came across with this config in .yml file.
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
Here, what exactly is the purpose of "waitTimeInMsWhenSyncEmpty"? Also what does "fetchRegistry" flag say?
Thank you.
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
Basically above three lines tells:
this instance to not register itself with the Eureka instance it finds, because that instance is.. itself.
Source :Spring Doc
Below are the individual statement level meanings:
Configuration tells eureka(client) to gets the registration information from the eureka server registry, the default is true
eureka:
client:
fetchRegistry: false
Configuration tells when the eureka server is started, you cannot wait for the instance registration information from the peer node. How long should it wait?source
eureka:
client:
server:
waitTimeInMsWhenSyncEmpty: 0
Usage : By default euraka server could act as both client and server.This is useful when we run multiple eureka servers to face SPOF issues.In this case , eureka could register both other microservice instances and naming server instances.

spring cloud discovery service - registering secure clients - healthCheckUrl

I have all clients (eureka instances) running with https. I have configured my eureka clients as mentioned in https://cloud.spring.io/spring-cloud-netflix/2.2.x/reference/html/#registering-a-secure-application
Everything in the config shown below works except the port information. Note that the config is clearly missing port information for all URLs, viz, statusPageUrl, healthCheckUrl and homePageUrl.
eureka:
instance:
nonSecurePortEnabled: false
securePortEnabled: true
**statusPageUrl: https://${eureka.hostname}/info**
**healthCheckUrl: https://${eureka.hostname}/health**
**homePageUrl: https://${eureka.hostname}/**
client:
serviceUrl:
defaultZone: ${EUREKA_SERVER}
healthcheck:
enabled: true
Since I have configured random port, I cannot hard code the port information in above urls. Could anyone please help me on this?
server:
port: 0

Can I Enrol One Micro services at 2 Different eureka

I don't know whether it is possible or not. I want to know whether I can enroll one microservice at two different eureka server at once.
I have one MS let say API-GATEWAY:
I want to enrol it on two different eureka registry server running on 8761 and 8762.
for that I write:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/ , http://localhost:8762/eureka/
registry-fetch-interval-seconds: 1000
instance:
hostname: api-gateway
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5000000
lease-expiration-duration-in-seconds: 5000000
First up all tell me is it possible or not?
If yes, what property should I use to achieve the objectives?
You can have only one defaultZone. You need peer replication. So that your 8761/eureka is synchronized with 8762/eureka. When the application is registered to 8761 it is also available in 8762. To do this see #spencergibb answer here.

Spring Cloud Turbine - Unable to handle multiple clients?

I’m having a bit of trouble getting Turbine to work in Spring Cloud. In a nutshell, I can’t determine how to configure it to aggregate circuits from more than one application at a time.
I have 6 separate services, a eureka server, and a turbine server running in standalone mode. I can see from my Eureka server that all of the services are registered, including turbine. My turbine server is up and running, and I can see its /hystrix page without issue. But when I try to use it to examine turbine.stream, I only see the FIRST server that is listed in turbine.appConfig, the rest are ignored.
This is my Turbine server’s application.yml, or at least the relevant parts:
---
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8010/eureka/
server:
port: 8030
info:
component: Turbine
turbine:
clusterNameExpression: new String(“default”)
appConfig: sentence,subject,verb,article,adjective,noun
management:
port: 8990
When I run this and access the hystrix dashboard on my turbine instance, asking for the turbine.stream, the ONLY circuit breakers listed in the output are for the first service listed in appConfig, the “sentence” service in this case. Curiously, if I re-arrange the order of these services and put another one first (like “noun”), I see only the circuits for THAT service. Only the first service in the list is displayed.
I’ll admit to being a little confused on some of the terminology, like streams, clusters, etc., so I could be missing some basic concept here, but my understanding is that Turbine could digest streams from more than one service and aggregate them in a single display. Suggestions would be appreciated.
I don't have enough reputation to comment, so I have to write this in an answer :)
I had the exactly same problem:
There are two services "test-service" and "other-service", each with it's own working hystrix-stream
and there is one Turbine-Application, which is configured like this:
turbine:
clusterNameExpression: new String("default")
appConfig: test-service,other-service
All of my services are running on my local machine.
Result is: My Hystrix-Dashboard just shows the metrics from "test-service".
Reason:
It seems to be, that a Turbine-Client which is configured the described way doesn't handle multiple services when they are running at the same host.
This is explained here:
https://github.com/Netflix/Hystrix/issues/117#issuecomment-14262713
Turbine maintains state of all these instances in order to maintain persistent connections to them and it does rely on the "hostname" and if the host name is the same then it won't instantiate a new connection to that same server (on a different port).
So the main point is, that all of your services must be registered with different hostnames. How you could do this on your local machine is described below.
UPDATE 2015-06-12/2016-01-23: Workaround for local testing
Change your hostfile:
# ...
127.0.0.1 localhost
127.0.0.1 localdomain1
127.0.0.1 localdomain2
# ...
127.0.0.1 localdomainx
And then set the hostname for your clients each to a different domain-entry like this:
application.yml:
eureka:
instance:
hostname: localdomainx

Resources