似乎可以根据任务定义运行任务或服务。任务和服务之间的区别和相似点是什么?在创建任务而不是服务时可以指定“任务组”这一事实中是否有线索?任务和服务在层次结构上是任务定义的相等实例化,还是服务由任务组成?
当前回答
任务定义是一个或多个容器配置的集合。有些任务可能只需要一个容器,而其他任务可能需要两个或更多潜在链接的容器并发运行。Task定义允许您指定使用哪个Docker映像、公开哪些端口、分配多少CPU和内存、如何收集日志以及定义环境变量。
Task是在直接运行Task时创建的,它会启动容器(在任务定义中定义),直到它们自行停止或退出,此时它们不会自动被替换。直接运行任务对于短时间运行的作业是理想的,也许可以作为通过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 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.
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.
更新:
我不确定用等级制来看待这些事情是否有帮助。
另一个非常重要的一点是,服务可以配置为使用负载均衡器,这样当它创建任务(即启动任务定义中定义的容器)时,服务将自动向负载均衡器注册容器的EC2实例。任务不能配置为使用负载均衡器,只有服务可以。
其他回答
@talentedmrjones用优美的语言解释了这一点。下面的图片将帮助你更容易地想象它:)
任务定义:(这是一个配置) 任务定义是应用程序的蓝图,通过属性描述一个或多个容器。一些属性是在任务级别上配置的,但大多数属性是在每个容器上配置的。
您正在定义容器以及如何通过任务定义启动它们。您将描述容器应该如何配置(链接到ECR保存的容器映像、CPU单元、内存、要公开的容器端口、网络类型)。
任务定义为你的应用程序(web)指定容器信息,比如你的任务中有多少容器,它们将使用什么资源,它们如何相互交互,以及它们将使用哪个主机端口。它可以是Fargate和EC2型。
任务定义:
这是描述要运行哪些Docker容器的蓝图,并代表您的应用程序。它包括几个任务。
服务:
Task Definition的一个实例。它还定义了一个Task Definition在任何给定时间运行的最小和最大任务、自动伸缩和负载平衡。
ECS容器实例:
这是一个运行Docker和ECS容器代理的EC2实例。Agent负责ECS和实例之间的通信,提供正在运行的容器的状态并管理正在运行的新容器。
关系:
任务定义是一个或多个容器配置的集合。有些任务可能只需要一个容器,而其他任务可能需要两个或更多潜在链接的容器并发运行。Task定义允许您指定使用哪个Docker映像、公开哪些端口、分配多少CPU和内存、如何收集日志以及定义环境变量。
Task是在直接运行Task时创建的,它会启动容器(在任务定义中定义),直到它们自行停止或退出,此时它们不会自动被替换。直接运行任务对于短时间运行的作业是理想的,也许可以作为通过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 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.
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.
更新:
我不确定用等级制来看待这些事情是否有帮助。
另一个非常重要的一点是,服务可以配置为使用负载均衡器,这样当它创建任务(即启动任务定义中定义的容器)时,服务将自动向负载均衡器注册容器的EC2实例。任务不能配置为使用负载均衡器,只有服务可以。
推荐文章
- AWS ECS中的任务和服务之间有什么区别?
- 亚马逊SimpleDB vs亚马逊DynamoDB
- 亚马逊ECS和亚马逊EC2有什么区别?
- 我如何知道我在S3桶中存储了多少对象?
- S3 Bucket操作不应用于任何资源
- 将AWS凭证传递给Docker容器的最佳方法是什么?
- 当权限为S3时,AccessDenied for ListObjects for S3 bucket:*
- 电子邮件地址未验证(AWS SES)
- 使用Boto3将S3对象作为字符串打开
- AWS VPC - Internet网关vs. NAT
- 如何在AWS Lambda中加载npm模块?
- 亚马逊S3 -如何修复“我们计算的请求签名与签名不匹配”错误?
- 警告:未受保护的私钥文件!当尝试SSH到Amazon EC2实例时
- 使用boto3连接CloudFront时,如何选择AWS配置文件
- 在亚马逊云服务器上设置FTP