阅读背景:

AWS ECS - 运行任务与服务

来源:互联网 

It appears that one can either run a Task or a Service based on a Task Definition. What are the differences and similarities between Task and Service? Is there a clue in the fact that one can specify "Task Group" when creating Task but not Service? Are Task and Service hierarchically equal instantiations of Task Definition, or is Service composed of Tasks?

似乎可以根据任务定义运行任务或服务。任务和服务之间有什么区别和相似之处?是否有一个线索,即在创建任务而不是服务时可以指定“任务组”?任务和服务是否在层次上等于任务定义的实例,或者是由任务组成的服务?

Thank you.

谢谢。

1 个解决方案

#1


82  

A Task Definition is a collection of 1 or more container configurations. Some Tasks may need only one container, while other Tasks may need 2 or more potentially linked containers running concurrently. The Task definition allows you to specify which Docker image to use, which ports to expose, how much CPU and memory to allot, how to collect logs, and define environment variables.

任务定义是一个或多个容器配置的集合。某些任务可能只需要一个容器,而其他任务可能需要同时运行2个或更多可能链接的容器。 Task定义允许您指定要使用的Docker镜像,要公开的端口,要分配的CPU和内存量,如何收集日志以及定义环境变量。

A Task is created when you run a Task directly, which launches container(s) (defined in the task definition) until they are stopped or exit on their own, at which point they are not replaced automatically. Running Tasks directly is ideal for short running jobs, perhaps as an example things that were accomplished via CRON.

直接运行任务时会创建一个任务,它会启动容器(在任务定义中定义),直到它们被停止或自行退出,此时它们不会自动替换。直接运行任务是短期运行工作的理想选择,也许是通过CRON完成的一个例子。

A Service is used to guarantee that you always have some number of Tasks running at all times. If a Task's container exits due to error, or the underlying EC2 instance fails and is replaced, the ECS Service will replace the failed Task. This is why we create Clusters so that the Service has plenty of resources in terms of CPU, Memory and Network ports to use. To us it doesn't really matter which instance Tasks run on so long as they run. A Service configuration references a Task definition. A Service is responsible for creating Tasks.

服务用于保证始终始终运行一定数量的任务。如果任务的容器由于错误而退出,或者底层的EC2实例失败并被替换,则ECS服务将替换失败的任务。这就是我们创建集群的原因,以便服务在CPU,内存和网络端口方面拥有足够的资源。对我们来说,只要它们运行,任务运行的实例并不重要。服务配置引用任务定义。服务负责创建任务。

Services are typically used for long running applications like web servers. For example, if I deployed my website powered by Node.JS in Oregon (us-west-2) I would want say at least three Tasks running across the three Availability Zones (AZ) for the sake of High-Availability; if one fails I have another two and the failed one will be replaced (read that as self-healing!). Creating a Service is the way to do this. If I had 6 EC2 instances in my cluster, 2 per AZ, the Service will automatically balance Tasks across zones as best it can while also considering cpu, memory, and network resources.

服务通常用于Web服务器等长期运行的应用程序。例如,如果我在俄勒冈州(us-west-2)部署由Node.JS支持的网站,我想要说至少有三个任务在高可用性的三个可用区(AZ)上运行;如果一个失败,我还有另外两个,失败的一个将被替换(读作自我治疗!)。创建服务是实现此目的的方法。如果我的群集中有6个EC2实例,每个AZ有2个,则服务将尽可能地自动平衡跨区域的任务,同时还要考虑cpu,内存和网络资源。

UPDATE:

更新:

I'm not sure it helps to think of these things hierarchically.

我不确定分层次地思考这些事情会有所帮助。

Another very important point is that a Service can be configured to use a load balancer, so that as it creates the Tasks—that is it launches containers defined in the Task Defintion—the Service will automatically register the container's EC2 instance with the load balancer. Tasks cannot be configured to use a load balancer, only Services can.

另一个非常重要的一点是,可以将服务配置为使用负载均衡器,以便在创建任务时 - 即启动任务定义中定义的容器 - 服务将自动使用负载均衡器注册容器的EC2实例。无法将任务配置为使用负载均衡器,只有服务可以。


分享到: