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

查看:38
本文介绍了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?

推荐答案

一个任务定义是一个或多个容器配置<的集合/strong>.有些任务可能只需要一个容器,而其他任务可能需要 2 个或更多潜在链接的容器同时运行.任务定义允许您指定要使用的 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 of things that were accomplished via CRON.

服务用于保证您始终有一定数量的任务始终运行.如果 Task 的容器因错误退出,或者底层 EC2 实例失败并被替换,ECS Service 将替换失败的 Task.这就是我们创建集群的原因,以便服务在 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 an 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.

服务通常用于网络服务器等长时间运行的应用程序.例如,如果我在俄勒冈州 (us-west-2) 部署了由 Node.JS 提供支持的网站,为了高可用性,我想说至少三个任务跨三个可用区 (AZ) 运行;如果一个失败,我还有另外两个,失败的将被替换(读作自我修复!).创建一个服务就是这样做的方法.如果我的集群中有 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.

另一个非常重要的一点是,可以将 Service 配置为使用负载均衡器,以便在它创建任务时(即启动任务定义中定义的容器),Service 将自动将容器的 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 Definition—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天全站免登陆