简体   繁体   English

Docker swarm的Netflix Eureka Server和Client实例注册问题

[英]Netflix Eureka Server and Client instance registration issue with Docker swarm

We are trying to deploy Netflix Eureka Server on Docker container which is a Spring Boot application. 我们正在尝试在Docker容器上部署Netflix Eureka Server,这是一个Spring Boot应用程序。 We are deploying it as a docker service with Docker swarm for container orchestration. 我们正在将它部署为Docker服务,使用Docker swarm进行容器编排。 Everything works fine when we directly create the container and run the application. 当我们直接创建容器并运行应用程序时,一切正常。 Eureka server registers all the client application with correct IP addresses. Eureka服务器使用正确的IP地址注册所有客户端应用程序。 But when we create and deploy it as docker service it registers the application with the wrong IP address. 但是当我们创建并部署它作为docker服务时,它会使用错误的IP地址注册应用程序。

We have tried below solution as per spring documentation, updated property values in our configuration files. 我们根据Spring文档尝试了以下解决方案,在配置文件中更新了属性值。


spring: 
   cloud:
     inetutils:
       ignoredInterfaces:
          - docker0
          - veth.*

eureka:
  instance:
    preferIpAddress: true

Tried these solutions as well: 尝试了这些解决方案:

https://github.com/spring-cloud/spring-cloud-netflix/issues/1820 https://github.com/spring-cloud/spring-cloud-netflix/issues/1820

https://github.com/spring-cloud/spring-cloud-netflix/issues/2084 https://github.com/spring-cloud/spring-cloud-netflix/issues/2084

While we run the docker service, the container gets assigned one IP address lets say 172.16.1.3 and service started inside docker gets assigned new IP address 172.16.1.4, because of this issue client application registers its self with container's IP into Eureka server. 当我们运行docker服务时,容器被分配一个IP地址让我们说172.16.1.3并且在docker内启动的服务被分配新的IP地址172.16.1.4,因为这个问题客户端应用程序将其自身与容器的IP注册到Eureka服务器。 But it is accessible with 172.16.1.4. 但它可以通过172.16.1.4访问。

So why running docker as service assigns two IP addresses? 那么为什么运行docker作为服务分配两个IP地址?

Here Eureka server is running on 10.255.53.172 IP address but as we can see in the second image it shows different IP in Instance Info 这里Eureka服务器运行在10.255.53.172 IP地址,但正如我们在第二张图片中看到的那样,它在Instance Info中显示不同的IP

Eureka instance is registered with containers IP but it's accessible with its service IP in the network Eureka实例在容器IP中注册,但可以通过网络中的服务IP访问

We use this configuration on production using docker swarm mode: 我们使用docker swarm模式在生产中使用此配置:

Eureka server configuration Eureka服务器配置

# Defines the Eureka server that is used by the Netflix OSS components to use as the registry
# for server discovery
eureka:
  instance:
    hostname: ${HOST_NAME:localhost}
    appname: eureka-cluster
    # enable to register multiple app instances with a random server port
    instance-id: ${spring.application.name}:${random.uuid}
    leaseRenewalIntervalInSeconds: 10
    leaseExpirationDurationInSeconds: 20

Eureka client configuration Eureka客户端配置

eureka:
  client:
    registerWithEureka: ${REGISTER_WITH_EUREKA:true}
    fetchRegistry: ${FETCH_REGISTRY:false}
    serviceUrl:
      defaultZone: ${EUREKA_DEFAULT_ZONE:http://localhost:8761/eureka/}
  instance:
    hostname: ${HOST_NAME:${spring.application.name}}  # work on swarm
    preferIpAddress: ${PREFER_IP_ADDRESS:false}
    # enable to register multiple app instances with a random server port
    instance-id: ${spring.application.name}:${random.uuid}
    leaseRenewalIntervalInSeconds: ${LEASE_RENEWAL_INTERVAl_IN_SECONDS:10}
    leaseExpirationDurationInSeconds: ${LEASE_EXPIRATION_DURATIONIN_SECONDS:20}

ON swarm service definition 关于群服务定义

  rd-service:
      image: my-eureka-server-microservice-image
    ports:
    - "8763:8763"
      networks:
      - backend

  client-service:
    image: my-eureka-client-microservice-image
    networks:
    - backend
    networks:
    environment:
    - "EUREKA_DEFAULT_ZONE=http://rd-service:8763/eureka"
    - "REGISTER_WITH_EUREKA=true"
    - "FETCH_REGISTRY=true"

networks:
  backend:
    external: true

Important: Services must be in the same docker overlay network used on eureka server docker service. 重要提示:服务必须位于eureka服务器docker服务上使用的同一个docker overlay网络中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker compose 中的 Eureka 客户端注册失败:无法注册为客户端 - 但 Eureka 服务器和客户端单独启动并运行 - Eureka Client Registration Failed in Docker compose: Failing to register as client - but eureka server & client is individually up & running 什么是尤里卡服务、尤里卡客户端、尤里卡实例和尤里卡服务器 - What is Eureka service, Eureka Client, Eureka instance and Eureka server Docker:客户端未连接到Eureka Server - Docker: Client not connecting to Eureka Server 为什么部署在Docker容器上的Spring Cloud Netflix应用程序需要显式设置eureka.instance.hostname? - Why do Spring Cloud Netflix applications deployed on Docker containers require explicitly setting eureka.instance.hostname? 我应该如何在EC2实例中包含的Docker中使用Netflix Zuul和Eureka配置Spring Cloud - How should I configure Spring Cloud with Netflix Zuul and Eureka in a Docker contained in an EC2 instance Eureka 客户端:com.netflix.discovery.shared.transport.TransportException:无法在任何已知服务器上执行请求 - Eureka client: com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server 使用Spring Cloud Netflix Eureka的Node.js客户端应用程序 - Node.js client application with Spring Cloud Netflix Eureka Spring Cloud:Eureka客户注册/注销周期 - Spring Cloud: Eureka Client registration/deregistration cycle Eureka服务器和Eureka客户端将Tomcat服务器分开 - Eureka server and eureka client to separate tomcat servers 尝试创建 Spring 启动 Netflix eureka 服务器时出错 - Getting Error while trying to create Spring boot Netflix eureka server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM