简体   繁体   中英

Spring Cloud Zookeeper and Feign deployed on AWS ECS with Fargate

I have two Spring Boot applications, both using Spring Cloud Zookeeper for service discovery, and one of them uses Feign to talk to the other, as described here

It all works fine when deployed on localhost and as docker images via docker-compose but when deploying as separate Tasks/Services to AWS ECS (using the default networking mode of awsvpc ), the communication between the two no longer works and the Feign client errors out with:

feign.FeignException$NotFound: [404 ] during [GET] to [http://my-api/api/workspace-context] [APIKeyService#getContextFromAPIKey(String)]: [<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} ... (431 bytes)]

Note that the response here kind of looks like the standard Tomcat 404 response.

I have seen the values stored in Zookeeper for this AWS deployment, and it seems it puts an IP address as the value for address , which I am not sure is correct.

{
    "name": "my-api",
    "id": "323be0b7-8ad8-4061-846e-abcdac2bbbca",
    "address": "169.254.xxx.xxx",
    "port": 8080,
    "sslPort": null,
    ...

This IP address matches neither the public nor the private IP of the ENI associated with the ECS task.

If I manually replace the address value of that Zookeeper entry with the ENI's public IP, it starts working corectly again (but not with the private IP). But obviously, it would be broken again after a new deployment.

Any help appreciated

Spring Cloud makes a guess as to what host or IP address to use. If there's an env var set on the host that contains the public IP you can use that to set the address .

spring.cloud.zookeeper.discovery.instanceIpAddress=${MY_IP_ENV_VAR}

Otherwise, according to the documentation , you can configure network interfaces to ignore:

spring:
  cloud:
    inetutils:
      ignoredInterfaces:
        - docker0
        - ecs-eth0 #ecs private network
        - veth.*

or what IP address ranges to prefer:

spring:
  cloud:
    inetutils:
      preferredNetworks:
        - 192.168
        - 10.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM