Search code examples
spring-bootamazon-ecsnetflix-eurekaspring-cloud-netflix

Unable to properly register service in Eureka on AWS ECS with dynamic ports on


I've recently inherited a micro-service system that runs on the spring-boot and netflix stack on AWS ECS, I'm quite new to spring-boot and the netflix side of things. I'm trying to move this over from using statically defined ports to using dynamic ports so that we can better use existing machines, but I'm having trouble getting the microservices to register themselves in Eureka.

The services are still starting up fine, when they are getting marked as offline in Spring Boot Admin. When I click on the service name in Spring Boot Admin I see the following links on the top right

http://10.128.83.113:32915/
http://10.128.83.113:18080/actuator
http://10.128.83.113:18080/actuator/health

10.128.83.113 is the IP address of this EC2 instance that is part of my ECS cluster, 32915 is the hostPort number that is being used inside the same machine and 18080 is the container port number that the service is binding to inside the docker container.

From reading the conversation at github.com I am setting the parameter eureka.instance.non-secure-port to the HostPort and that seems to be setting the port on the topmost of the three links, and from reading medium.com linked to from github.com I am also setting

eureka.instance.preferIpAddress=true 
eureka.instance.ip-address=\${HOST_IP} 

This is all working fine without the three eureka config items above when I'm using a host network mode in ECS/docker and statically defined ports, but that requires more EC2 instances in a cluster than is necessary. When I change to using dynamic ports and a bridge network mode (due to the dynamic ports), I just can't get the service to register itself properly in Eureka, I think I'm getting close, but I can't workout what config I'm missing. Can someone advise on how to go about solving this? I suspect something is registering the IP address of the docker container or the docker container port number (or both) with Eureka, but I can't see where in Eureka to find logs to confirm/deny that and I don't know what other config I should be setting.

The microsevices are using spring boot v2.0.3.release. ECS is 1.20.3


Solution

  • So I have managed to get this working, in the end I needed to set 6 parameters they are:

    eureka.instance.non-secure-port=${EXPOSED_PORT}
    eureka.instance.preferIpAddress=true
    eureka.instance.ip-address=${HOST_IP}
    eureka.instance.hostname=${HOST_NAME}
    eureka.instance.metadataMap.management.port=${EXPOSED_PORT}
    eureka.instance.health-check-url=${HOST_IP}:${EXPOSED_PORT}/actuator/health
    

    All of these together have the service registered successfully in Eureka.