简体   繁体   English

使用应用程序负载均衡器在aws ECS上进行服务发现

[英]Service discovery on aws ECS with Application Load Balancer

I would like to ask you if you have an microservice architecture (based on Spring Boot) involving Amazon Elastic Container Service (ECS) with Application Load Balancer(ALB), service discovery is performed automatically by the platform, or do you need a special mechanism (such as Eureka or Consul)? 我想问你是否有一个涉及Amazon Elastic Container Service(ECS)和应用程序负载均衡器(ALB)的微服务架构(基于Spring Boot),服务发现是由平台自动执行的,还是需要一个特殊的机制(如尤里卡或领事)?

From the documentation (ECS and ALB) is not clear you have this feature provided. 从文档(ECS和ALB)不清楚您是否提供此功能。

I have talked this with the Amazon support team and they respond the following: "...using Service Discovery on AWS ECS[..] just with ALBs. 我已经与亚马逊支持团队讨论了这个问题,他们回应了以下内容:“......在AWS ECS上使用服务发现[...]只需使用ALB。

So, there could be three options here: 1) Using ALB/ELB as service endpoints (Target groups for ALBs, separate ELBs if using ELBs) 因此,这里可以有三个选项:1)使用ALB / ELB作为服务端点(ALB的目标组,如果使用ELB则使用单独的ELB)

2) Using Route53 and DNS for Service Discovery 2)使用Route53和DNS进行服务发现

3) Using a 3rd Party product like Consul.io in combination with Nginx. 3)将Consul.io等第三方产品与Nginx结合使用。

Let me speak about each of these options. 让我谈谈这些方案中的每一个。

Using ALBs/ELBs 使用ALB / ELB

For this option the idea is to use the ELBs or ALB Target groups in front of each service. 对于此选项,我们的想法是在每个服务前使用ELB或ALB目标组。 We define an Amazon CloudWatch Events filter which listens to all ECS service creation messages from AWS CloudTrail and triggers an Amazon Lambda function. 我们定义了一个Amazon CloudWatch Events过滤器,该过滤器侦听来自AWS CloudTrail的所有ECS服务创建消息并触发Amazon Lambda函数。 This function identifies which Elastic Load Balancing load balancer (or an ALB Target group) is used by the new service and inserts a DNS resource record (CNAME) pointing to it, using Amazon Route 53. The Lambda function also handles service deletion to make sure that the DNS records reflect the current state of applications running in your cluster. 此功能使用Amazon Route 53识别新服务使用哪个Elastic Load Balancing负载均衡器(或ALB目标组)并插入指向它的DNS资源记录(CNAME).Lambda函数还处理服务删除以确保DNS记录反映了群集中运行的应用程序的当前状态。

The down side here is that it can incur higher costs if you are using ELBs - as you need an ELB for each service. 这里的缺点是,如果您使用ELB,它可能会产生更高的成本 - 因为您需要为每项服务使用ELB。 And it might not be the simplest solution out there. 它可能不是最简单的解决方案。 If you wish to read more on this you can do so here[1] 如果您想了解更多信息,请点击此处[1]

Using Route53 使用Route53

This approach involves the use of Route53 and running a simple agent[2] on your ECS container instances. 这种方法涉及使用Route53并在ECS容器实例上运行简单代理[2]。 As your containers stop/start the agent will update the Route53 DNS records. 当您的容器停止/启动时,代理将更新Route53 DNS记录。 It creates a SRV record. 它创建了一个SRV记录。 Likewise it will delete said records once the container is stopped. 同样,一旦容器停止,它将删除所述记录。

Another part of this method is a Lambda function that performs health checks on ECS container instances - and removes them from R53 in case of a failure. 此方法的另一部分是Lambda函数,该函数对ECS容器实例执行运行状况检查 - 并在发生故障时将其从R53中删除。

You can read up more on this method, on our blog post here[3]. 您可以在我们的博客文章[3]上阅读有关此方法的更多信息。

Using a 3rd Party tool like Consul.io Using tools like Consul.io on ECS, will work - but is not supported by AWS. 使用像Consul.io这样的第三方工具在ECS上使用像Consul.io这样的工具,但是不支持AWS。 So you are free to use it, but we - unfortunately - do not offer support for it. 所以你可以自由使用它,但我们 - 不幸的是 - 不提供支持。

So, in conclusion - there are a few ways of implementing service discovery on AWS ECS - the two ways I showed here that use AWS resources, and of course the way of using 3rd party applications. 总而言之 - 在AWS ECS上有几种实现服务发现的方法 - 我在这里展示的两种使用AWS资源的方式,当然还有使用第三方应用程序的方式。 "

you dont have an out-of-the-box solution in AWS, although it is possible with some effort as described in https://aws.amazon.com/es/blogs/compute/service-discovery-an-amazon-ecs-reference-architecture/ 您在AWS中没有开箱即用的解决方案,尽管可以通过https://aws.amazon.com/es/blogs/compute/service-discovery-an-amazon-ecs中的描述进行一些努力-reference架构/

You may also install Zuul + Ribbon + Eureka or Nginx + Consul and use ALB to distribute traffic among Zuul or Nginx 您也可以安装Zuul + Ribbon + Eureka或Nginx + Consul并使用ALB在Zuul或Nginx之间分配流量

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

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