AWS ECS中的任务和服务有什么区别? [英] What is the difference between a task and a service in AWS ECS?

查看:719
本文介绍了AWS ECS中的任务和服务有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎可以基于任务定义运行任务或服务.任务和服务之间有什么区别和相似之处?在创建Task时可以指定任务组",但不能在Service时指定线索吗?任务和服务在层次上是等同于任务定义的实例化,还是服务由任务组成?

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?

推荐答案

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

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.

直接运行任务时,会创建一个任务,该任务将启动容器(在任务定义中定义),直到它们停止或自行退出为止,此时它们是不会自动替换.直接运行任务是短期任务的理想选择,例如通过CRON完成的事情.

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.

服务用于确保您始终有一定数量的正在运行的任务.如果任务的容器由于错误而退出,或者基础EC2实例失败并被替换,则ECS服务将替换失败的任务.这就是为什么我们创建 集群 的原因,以便该服务在要使用的CPU,内存和网络端口方面具有大量资源.对我们而言,任务在哪个实例上运行并不重要,只要它们在运行即可.服务配置引用任务定义.服务负责创建任务.

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.

服务通常用于长时间运行的应用程序,例如Web服务器.例如,如果我在俄勒冈州(us-west-2)部署了由Node.JS支持的网站,那么我想说要在三个可用区(AZ)上至少运行三个任务,以实现高可用性;如果一个失败了,我还有另外两个,失败的一个将被替换(读作 self-healing !).创建服务是实现此目的的方法.如果我的群集中有6个EC2实例(每个可用区2个),则该服务将自动尽力在各个区域之间平衡任务,同时还要考虑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.

更新:

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

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

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

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.

这篇关于AWS ECS中的任务和服务有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆