简体   繁体   English

Amazon ECS 和 Amazon EC2 有什么区别?

[英]What is the difference between Amazon ECS and Amazon EC2?

I'm just getting started on AWS EC2.我刚刚开始使用 AWS EC2。 I understand that EC2 is like a remote computer where I can do pretty much everything I want.我知道 EC2 就像一台远程计算机,我几乎可以在其中做任何我想做的事情。 Then I found out about ECS.然后我发现了ECS。 I know it uses Docker, but I'm confused about the relationship between these two.我知道它使用 Docker,但我对这两者之间的关系感到困惑。

Is ECS just a Docker install in EC2? ECS 只是 EC2 中的 Docker 安装吗? If I already have an EC2 and I start an ECS, does it mean I have two instances?如果我已经有一个 EC2 并且我启动了一个 ECS,这是否意味着我有两个实例?

Your question你的问题

Is ECS just a docker install in EC2? ECS 只是 EC2 中的 docker 安装吗? If I already have a EC2, then I start a ECS, does it mean I have two instance?如果我已经有一个EC2,那么我启动一个ECS,是否意味着我有两个实例?

No. AWS ECS is just a logical grouping (cluster) of EC2 instances, and all the EC2 instances part of an ECS act as Docker host ie ECS can send command to launch a container on them ( EC2 ).AWS ECS只是EC2实例的逻辑分组(集群), ECS的所有EC2实例部分都充当Docker主机,即 ECS 可以发送命令以在它们上启动容器( EC2 )。 If you already have an EC2, and then launch ECS, you'll still have a single instance.如果您已经有一个 EC2,然后启动 ECS,您仍然会有一个实例。 If you add/register (by installing the AWS ECS Container Agent) the EC2 to ECS it'll become the part of the cluster, but still a single instance of EC2.如果您将 EC2 添加/注册(通过安装 AWS ECS 容器代理)到 ECS,它将成为集群的一部分,但仍然是 EC2 的单个实例。

An Amazon ECS without any EC2 registered (added to the cluster) is good for nothing.没有注册任何 EC2(添加到集群)的 Amazon ECS 毫无用处。


TL; TL; DR博士

An overview概述

  • EC2 - is simply a remote (virtual) machine. EC2 - 只是一台远程(虚拟)机器。
  • ECS stands for Elastic Container Service - as per basic definition of computer cluster , ECS is basically a logical grouping of EC2 machines/instances . ECS代表Elastic Container Service - 根据计算机集群的基本定义, ECS基本上是EC2机器/实例的逻辑分组 Technically speaking ECS is a mere configuration for an efficient use and management of your EC2 instance(s) resources ie storage, memory, CPU, etc.从技术上讲, ECS只是一种用于有效使用和管理EC2实例资源(即存储、内存、CPU 等)的配置。

To simplify it further, if you have launched an Amazon ECS with no EC2 instances added to it, it's good for nothing ie you can't do anything about it.为了进一步简化它,如果您启动了一个没有添加任何EC2实例的Amazon ECS ,那么它没有任何好处,即您对此无能为力。 ECS makes sense only once one (or more) EC2 instances are added to it. ECS只有在一个(或多个) EC2实例被添加到它时才有意义。

The next confusing thing here is the container term - which is not fully virtualized machine instances, and Docker is one technology we can use to create container instances.下一个令人困惑的是容器术语——它不是完全虚拟化的机器实例,而Docker是我们可以用来创建容器实例的一种技术。 Docker is a utility you can install on our machine, which makes it a Docker host, and on this host you can create containers (same as virtual machines - but much more light-weight). Docker是一个可以安装在我们机器上的实用程序,这使它成为一个Docker主机,并且在这个主机上你可以创建容器(与虚拟机相同 - 但更轻量级)。 To sum up, ECS is just about clustering of EC2 instances, and uses Docker to instantiate containers/instances/virtual machines on these ( EC2 ) hosts .综上所述, ECS就是 EC2 实例的集群,使用Docker在这些( EC2 )主机上实例化容器/实例/虚拟机

All you need to do is launch an ECS , and register/add as much EC2 instances to it as you need.您需要做的就是启动一个ECS ,并根据需要向其中注册/添加尽可能多的EC2实例。 You can add/register EC2 instances, all you need is Amazon ECS Container Agent running on your EC2 instance/machine, which can be done manually or directly using the special AMI (Amazon Machine Image) ie Amazon ECS-optimized AMI, which already has the Amazon ECS Container Agent.您可以添加/注册 EC2 实例,您所需要的只是在您的 EC2 实例/机器上运行的 Amazon ECS 容器代理,这可以手动完成,也可以直接使用特殊的 AMI(Amazon 系统映像)即 Amazon ECS-optimized AMI,它已经有Amazon ECS 容器代理。 During the launch of a new EC2 instance the Agent automatically registers it to the default ECS cluster.在启动新 EC2 实例期间,代理会自动将其注册到默认 ECS 集群。

The container agent running on each of the instances ( EC2 instances) within an Amazon ECS cluster sends information about the instance's current running tasks and resource utilization to Amazon ECS, and starts and stops tasks whenever it receives a request from Amazon ECS.Amazon ECS集群内的每个实例( EC2实例)上运行的容器代理将有关实例当前正在运行的任务和资源利用率的信息发送到 Amazon ECS,并在收到来自 Amazon ECS 的请求时启动和停止任务。 For more information, see Amazon ECS Container Agent .有关更多信息,请参阅Amazon ECS 容器代理 Once set, each of the created container instances (of whatever EC2 machine/node) will be an instance in Amazon ECS 's swarm.设置后,每个创建的容器实例(无论EC2机器/节点)都将成为Amazon ECS群中的一个实例。


For more information – read step 10 from this documentation: Launching an Amazon ECS Container Instance :有关更多信息 – 请阅读本文档中的第 10 步:启动 Amazon ECS 容器实例

Choose an AMI for your container instance.为您的容器实例选择一个 AMI。 You can choose the Amazon ECS-optimized AMI, or another operating system, such as CoreOS or Ubuntu.您可以选择 Amazon ECS 优化的 AMI,或其他操作系统,例如 CoreOS 或 Ubuntu。 If you do not choose the Amazon ECS-optimized AMI, you need to follow the procedures in Installing the Amazon ECS Container Agent .如果您不选择 Amazon ECS 优化的 AMI,则需要按照安装 Amazon ECS 容器代理中的步骤进行操作。

By default, your container instance launches into your default cluster.默认情况下,您的容器实例会启动到您的默认集群中。 If you want to launch into your own cluster instead of the default, choose the Advanced Details list and paste the following script into the User data field, replacing your_cluster_name with the name of your cluster.如果要启动到您自己的集群而不是默认集群,请选择 Advanced Details 列表并将以下脚本粘贴到 User data 字段中,将 your_cluster_name 替换为您的集群名称。

 #!/bin/bash echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config

Or, if you have an ecs.config file in Amazon S3 and have enabled Amazon S3 read-only access to your container instance role, choose the Advanced Details list and paste the following script into the User data field, replacing your_bucket_name with the name of your bucket to install the AWS CLI and write your configuration file at launch time.或者,如果您在 Amazon S3 中有一个 ecs.config 文件并启用了对您的容器实例角色的 Amazon S3 只读访问权限,请选择 Advanced Details 列表并将以下脚本粘贴到 User data 字段中,将 your_bucket_name 替换为您的存储桶以安装 AWS CLI 并在启动时编写您的配置文件。 Note For more information about this configuration, see Storing Container Instance Configuration in Amazon S3. Note 有关此配置的更多信息,请参阅在 Amazon S3 中存储容器实例配置。

 #!/bin/bash yum install -y aws-cli aws s3 cp s3://your_bucket_name/ecs.config /etc/ecs/ecs.config

Just to clarify it further – you can create containers on your single EC2 instance without ECS .只是为了进一步澄清——您可以在没有ECS的情况下在单个EC2实例上创建容器。 Install any of the containerization technology ie Docker and run the create container command, setting your EC2 as a Docker host, and have as much Docker containers as you want (or as much as your EC2 's resources allow).安装任何容器化技术,即Docker并运行 create container 命令,将您的EC2设置为Docker主机,并拥有尽可能多的Docker容器(或尽可能多的EC2资源允许)。

In simple words,ECS is a manager while EC2 instances are just like employees.简单来说,ECS 是管理者,而 EC2 实例就像员工。 All the employees (EC2) under this manager(ECS) can perform "Docker" tasks and the manager also understands "docker" pretty well.该经理(ECS)下的所有员工(EC2)都可以执行“Docker”任务,经理也非常了解“docker”。 So,whenever you need "docker" resources, you show up to the Manager.因此,每当您需要“docker”资源时,您都会出现在 Manager 面前。 Manager already has status from every employee(EC2) decides which one should perform the task.经理已经从每个员工(EC2)那里获得状态来决定应该由哪个员工来执行任务。

Now, coming back to your question, a manager without an "employee" does not make sense but is definitely possible.现在,回到您的问题,没有“员工”的经理没有意义,但绝对有可能。

在此处输入图像描述

EC2 allows you to launch individual instances which you can use for pretty much whatever you like. EC2 允许您启动单个实例,您可以将其用于几乎任何您喜欢的事情。 ECS is a container service, which means it will launch instances that will be ready to launch container applications. ECS 是一种容器服务,这意味着它将启动准备启动容器应用程序的实例。 The main distinction between the two services is that with EC2 you have to manage each instance separately in whatever method you choose (manually, using a CM tool or any other way) - deploy your applications and maintain the connection between the servers yourself.这两种服务之间的主要区别在于,使用 EC2,您必须以您选择的任何方法(手动、使用 CM 工具或任何其他方式)单独管理每个实例 - 部署您的应用程序并自己维护服务器之间的连接。 ECS allows you to launch a cluster of machines that will serve as the deployment ground of your container apps, allowing you to treat all instances in the cluster as one big instance available for your container workload. ECS 允许您启动将用作容器应用程序部署基础的机器集群,允许您将集群中的所有实例视为一个可用于容器工作负载的大实例。

And to answer your question - You can start an ECS cluster with no instances in it, but then it won't be able to run anything on it.并回答您的问题 - 您可以启动一个没有实例的 ECS 集群,但随后它将无法在其上运行任何东西。 Once you register an EC2 instance inside an ECS cluster, containers are ready to run in it.在 ECS 集群中注册 EC2 实例后,容器就可以在其中运行了。 So the bottom line is - you can use both ECS and EC2 with only one instance, but that is not the actual use case these services were built for.所以底线是 - 您可以仅使用一个实例同时使用 ECS 和 EC2,但这并不是这些服务的实际用例。

Put simply, Elastic Container Service (ECS) is a Docker container orchestration service.简单来说,弹性容器服务(ECS)是一个 Docker 容器编排服务。

You can ask it to run one or more Docker images, either as an auto-scaling capable " Service " or as an ad-hoc " Task ".您可以要求它运行一个或多个 Docker 映像,作为具有自动缩放功能的“服务”或作为临时的“任务”。

The services and tasks run on a " Cluster ".服务和任务在“集群”上运行。 Originally, a Cluster was a group of one or more pre-configured EC2 servers running ECS Cluster Agent.最初,集群是一组运行 ECS 集群代理的一个或多个预配置 EC2 服务器。 The Cluster Agent would schedule the containers on the EC2 server.集群代理会在 EC2 服务器上调度容器。 These EC2 servers show up in your EC2 Instances list and are charged at regular EC2 per-minute costs - You can even SSH onto them like any normal EC2 server.这些 EC2 服务器显示在您的 EC2 实例列表中,并按常规 EC2 每分钟费用收费 - 您甚至可以像任何普通 EC2 服务器一样通过 SSH 连接到它们。 If you wanted more capacity to run more Services or Tasks, or if you wanted resilience against EC2 failure, then you would more EC2 servers.如果您想要更多容量来运行更多服务或任务,或者如果您想要抵御 EC2 故障,那么您需要更多 EC2 服务器。

Around November 2017, AWS added ECS Fargate . 2017 年 11 月左右,AWS 添加了 ECS Fargate Now a Cluster can run "serverless" without provisioning EC2 nodes.现在集群可以在不配置 EC2 节点的情况下运行“无服务器”。 You simply define the amount of CPU and memory your Task or Service requires to operate, meaning that you just pay for the CPU and memory time rather than the EC2.您只需定义任务或服务运行所需的 CPU 和内存量,这意味着您只需为 CPU 和内存时间而不是 EC2 付费。

ECS stands for ' Elastic Container Service '. ECS 代表“弹性容器服务”。 It is a container orchestration service.它是一个容器编排服务。
Lets say you have a Docker container running and you decide to update the Docker image.假设您有一个 Docker 容器正在运行,并且您决定更新 Docker 映像。 It's relatively easy task to stop, pull and run if you have one container running but its tedious to do the same steps if you have 10 to 100 of containers running.如果您有一个容器正在运行,那么停止、拉动和运行是相对容易的任务,但如果您有 10 到 100 个容器正在运行,那么执行相同的步骤就很乏味了。
With AWS ECS you can have this control.使用AWS ECS ,您可以拥有此控制权。 You specify if update is required provide the latest image id and ECS will handle the stop, pull and run etc. commands for you.您指定是否需要更新,提供最新的镜像 ID, ECS将为您处理停止、拉取和运行等命令。 It also provides with much more additional features, refer - https://aws.amazon.com/ecs/features/它还提供了更多附加功能,请参阅 - https://aws.amazon.com/ecs/features/
EC2 stand for ' Elastic Compute Cloud '. EC2 代表“弹性计算云”。 In simple terms its a virtual machine.简单来说,它是一个虚拟机。
ECS uses EC2 to run your containers. ECS使用EC2运行您的容器。
'These running docker containers (tasks) are run on EC2 instances' . '这些正在运行的 docker 容器(任务)在 EC2 实例上运行'

Okay, as you know EC2 is a virtual machine on AWS and ECS is a container orchestration system on AWS.好的,如您所知,EC2 是 AWS 上的虚拟机,而 ECS 是 AWS 上的容器编排系统。

To use ECS, you need to run your container into some virtual machines which EC2 is one of an option to provide that.要使用 ECS,您需要将容器运行到一些虚拟机中,EC2 是提供该选项的选项之一。

You will need to install ecs-agent on EC2 to make a connection with ECS.您需要在 EC2 上安装ecs-agent才能与 ECS 建立连接。 And ECS also can monitor the resource usages on your EC2. ECS 还可以监控 EC2 上的资源使用情况。 So basically you choose the more high-level EC2 type, then more resource(CPU/MEM) your container can use.所以基本上你选择更高级的 EC2 类型,然后你的容器可以使用更多的资源(CPU/MEM)。

ECS is a container orchestrator just like Kubernetes or Docker swarm, EC2 is an Amazon Elastic Compute Cloud platform for Creating Virtual Machines. ECS 是一个容器编排器,就像 Kubernetes 或 Docker swarm 一样,EC2 是一个用于创建虚拟机的 Amazon Elastic Compute Cloud 平台。 ECS allows you to run containers on either serverless environments (Fargate) where you don't have to run any VM or in a non managed environments where you host the containers on EC2 instances. ECS 允许您在无需运行任何 VM 的无服务器环境 (Fargate) 或在 EC2 实例上托管容器的非托管环境中运行容器。

EC2 是一项使应用程序能够在 AWS 上运行的计算服务,而 ECS 是一项主要用于编排 Docker 容器的 AWS 服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM