eureka
eureka copied to clipboard
Eureka with AWS ECS Fargate
I am deploying spring cloud application onto AWS ECS. I updated my eureka client with overriding EurekaInstanceConfigBean as to register with IP address. It is working well with launch type EC2 but failing with Fargate. Here is my configuration. I can see null values in the system logs.
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
EurekaInstanceConfigBean b = new EurekaInstanceConfigBean(inetUtils);
AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
b.setDataCenterInfo(info);
info.getMetadata().put(AmazonInfo.MetaDataKey.publicHostname.getName(), info.get(AmazonInfo.MetaDataKey.publicIpv4));
System.out.println("*********************Public Host Name******************************* " + info.get(AmazonInfo.MetaDataKey.publicHostname));
System.out.println("*********************Public IPV4 ******************************* " + info.get(AmazonInfo.MetaDataKey.publicIpv4));
System.out.println("*********************Local IPV4******************************* " + info.get(AmazonInfo.MetaDataKey.localIpv4));
b.setHostname(info.get(AmazonInfo.MetaDataKey.publicHostname));
b.setIpAddress(info.get(AmazonInfo.MetaDataKey.publicIpv4));
b.setNonSecurePort(port);
return b;
}
@dulimitta by default eureka client queries the EC2 metadata endpoint for system information. I have not used Fargate yet, but I suspect perhaps this endpoint is not available within Fargate.
If that is the case, instead of autoBuild()
, you'll want to manually create the AmazonInfo
object with system information provided in other ways.
Sorry for the late reply. How would I get system information in other ways? Can you please suggest.
Fargate platform version 1.1 seems to support metadata for ECS. See anouncement.
I think that eureka-client does not support this. See AmazonInfo.java
In case anyone already has implemented this could you please point me to that. Anyway, it would be great to have eureka-client to support ECS (and especially Fargate).
One way to get metadata is to do it as described here.
I created a sample how to do this. Hope this helps!
Thank you @jussiseppala. I will look into it. We are using ECS with EC2 for now.
Was this case resolved, can somebody post on how to get the container ip and port from the ecs containers (services) and send it to Eureka Server (ecs container).
@Sridharc20 we are using ECS with EC2. You can refer to @jussiseppala the last comment to get the container IP.
Can we reopen this please? I would like to use Eureka on a Fargate cluster and it would be nice if Eureka supported this out of the box without me having to do hackity hacks.
I think I almost have it figured out, I could open a PR once I do. I am using Spring Cloud though...but my understanding is that configuration for integrating Eureka with Fargate should live here and not as a part of Spring Cloud project.
Reopened, happy to accept a PR with any examples.
@mjohns39 did you made it?
@troshko111 I am facing same issue when I register my micro service with euraka it pick wrong ip address. I saw the sample created by @jussiseppala but that will make the code platform specific and I have to replicate that configuration in every micro service. Please let me know how we can fix this issue. If it's already fix please let me know the fix version.
@shahbaz07 did you get it?
@ChristianEGB I didn't check this but I fixed this by adding below code in application class. But if it's fixed already please let me know the fixed version.
@Bean open fun eurekaInstanceConfig(inetUtils: InetUtils?): EurekaInstanceConfigBean? { inetUtils?.let { val config = EurekaInstanceConfigBean(inetUtils) var ip: String? = null try { ip = InetAddress.getLocalHost().hostAddress } catch (e: UnknownHostException) { e.printStackTrace() } config.ipAddress = ip config.nonSecurePort = getPort() config.isPreferIpAddress = true return config } return null }
open fun getPort(): Int { return 0 }
@shahbaz07 Will check and I will let yoo know, thanks.
@ChristianEGB Thanks.
@ChristianEGB is there any update on this?
Did anyone figure out how to fix this issue?
@shahbaz07 @anirbandutta9 in my case I removed Eureka from my infra and I replaced that with the service discovery that AWS ECS already has.
Yes. I figured it out. Apologies, I completely forgot to push a PR. I will try and do a gist or something at least today...and try to push PR this weekend
Yes. I figured it out. Apologies, I completely forgot to push a PR. I will try and do a gist or something at least today...and try to push PR this weekend
@mjohns39 Much appreciate ..thanks
@shahbaz07 @anirbandutta9 in my case I removed Eureka from my infra and I replaced that with the service discovery that AWS ECS already has.
@shahbaz07 We will see if we can implement service discovery in our environment .. Did you get any reference articles on how to do it?
Here is a gist: https://gist.github.com/mjohns39/e1f8881620292329b408465a982dc7b8. I also added the POJOs you'll need. Worth mentioning that it's basically identical to jussiseppala solution here. The minor difference is that I didn't need to use AmazonInfo
Edit: The tricky part is you essentially need to grab the private IP Address from the ECS Task Metadata and then override the destination IP Address with that private IP Address. You'll only know what that IP address is though at runtime since it is Fargate