本文介绍了使用Application Load Balancer在AWS ECS上进行服务发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问您,如果您有一个微服务架构(基于Spring Boot),该架构涉及带有Application Load Balancer(ALB)的Amazon Elastic Container Service(ECS),服务发现是由平台自动执行的,还是您需要?一种特殊的机制(例如Eureka或Consul)?

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)?

不清楚文档(ECS和ALB)是否已提供此功能.

From the documentation (ECS and ALB) is not clear you have this feature provided.

推荐答案

我已经与Amazon支持团队进行了交谈,他们回应如下:"...仅在ALB上使用AWS ECS [..]上的服务发现.

I have talked this with the Amazon support team and they respond the following:"...using Service Discovery on AWS ECS[..] just with ALBs.

因此,这里可能有三个选项:1)使用ALB/ELB作为服务端点(ALB的目标组,如果使用ELB,则单独的ELB)

So, there could be three options here: 1) Using ALB/ELB as service endpoints (Target groups for ALBs, separate ELBs if using ELBs)

2)使用Route53和DNS进行服务发现

2) Using Route53 and DNS for Service Discovery

3)结合使用Consul.io之类的第三方产品与Nginx.

3) Using a 3rd Party product like Consul.io in combination with Nginx.

让我谈谈这些选项中的每一个.

Let me speak about each of these options.

对于此选项,想法是在每个服务之前使用ELB或ALB目标组.我们定义了一个Amazon CloudWatch Events过滤器,该过滤器侦听来自AWS CloudTrail的所有ECS服务创建消息并触发Amazon Lambda函数.此功能标识新服务使用哪个Elastic Load Balancing负载均衡器(或ALB目标组),并使用Amazon Route 53插入指向该负载均衡器的DNS资源记录(CNAME).Lambda函数还处理服务删除操作,以确保DNS记录反映集群中正在运行的应用程序的当前状态.

For this option the idea is to use the ELBs or ALB Target groups in front of each service.We define an Amazon CloudWatch Events filter which listens to all ECS service creation messages from AWS CloudTrail and triggers an Amazon Lambda function. 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.

这里的缺点是,如果您使用ELB,则可能会产生更高的成本-因为每种服务都需要一个ELB.而且它可能不是最简单的解决方案.如果您想了解更多,可以在这里[1]

The down side here is that it can incur higher costs if you are using ELBs - as you need an ELB for each service. And it might not be the simplest solution out there.If you wish to read more on this you can do so here[1]

此方法涉及使用Route53并在ECS容器实例上运行简单的代理[2].当您的容器停止/启动时,代理将更新Route53 DNS记录.它创建一个SRV记录.同样,一旦容器停止,它将删除所述记录.

This approach involves the use of Route53 and running a simple agent[2] on your ECS container instances. As your containers stop/start the agent will update the Route53 DNS records. It creates a SRV record. Likewise it will delete said records once the container is stopped.

该方法的另一部分是Lambda函数,该函数对ECS容器实例执行运行状况检查-如果发生故障,则将它们从R53中删除.

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.

您可以在此处的博客文章[3]中详细了解此方法.

You can read up more on this method, on our blog post here[3].

因此,总而言之-有几种在AWS ECS上实现服务发现的方法-我在这里展示的两种使用AWS资源的方法,当然还有使用第三方应用程序的方法."

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."

这篇关于使用Application Load Balancer在AWS ECS上进行服务发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:32