我刚刚开始使用AWS EC2。我知道EC2就像一台远程计算机,在那里我可以做几乎所有我想做的事情。然后我发现了ECS。我知道它使用Docker,但我对这两者之间的关系感到困惑。
ECS只是EC2中的Docker安装吗? 如果我已经有一个EC2并且我启动了一个ECS,这是否意味着我有两个实例?
我刚刚开始使用AWS EC2。我知道EC2就像一台远程计算机,在那里我可以做几乎所有我想做的事情。然后我发现了ECS。我知道它使用Docker,但我对这两者之间的关系感到困惑。
ECS只是EC2中的Docker安装吗? 如果我已经有一个EC2并且我启动了一个ECS,这是否意味着我有两个实例?
EC2 allows you to launch individual instances which you can use for pretty much whatever you like. ECS is a container service, which means it will launch instances that will be ready to launch container applications. 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. 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集群,但是这样它就不能在上面运行任何东西。一旦在ECS集群中注册了EC2实例,容器就可以在其中运行了。因此,底线是—您可以仅对一个实例同时使用ECS和EC2,但这不是构建这些服务的实际用例。
你的问题
ECS仅仅是安装在EC2中的docker吗?如果我已经有了EC2,那么我 启动ECS,这是否意味着我有两个实例?
不。AWS ECS只是EC2实例的逻辑分组(集群),ECS的所有EC2实例都充当Docker主机,即ECS可以发送命令在它们(EC2)上启动容器。 如果您已经有一个EC2,然后启动ECS,那么您仍然只有一个实例。如果您添加/注册(通过安装AWS ECS容器代理)EC2到ECS,它将成为集群的一部分,但仍然是EC2的单个实例。
没有注册任何EC2(添加到集群)的Amazon ECS毫无用处。
TL;博士
概述
EC2—只是一个远程(虚拟)机器。 ECS代表弹性容器服务-根据计算机集群的基本定义,ECS基本上是一个逻辑分组 EC2机器/实例。从技术上讲,ECS是一个纯粹的 配置,以便有效地使用和管理EC2 实例资源,即存储、内存、CPU等。
为了进一步简化,如果你已经启动了一个Amazon ECS,但没有添加EC2实例,那么它是没有用的,也就是说你对它什么都做不了。只有将一个(或多个)EC2实例添加到ECS中,ECS才有意义。
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 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). 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实例。你可以添加/注册EC2实例,你所需要的只是在你的EC2实例/机器上运行亚马逊ECS容器代理,这可以手动完成,也可以直接使用特殊的AMI(亚马逊机器映像),即亚马逊ECS优化的AMI,它已经有亚马逊ECS容器代理。在启动新的EC2实例期间,代理会自动将其注册到默认的ECS集群。
运行在Amazon ECS集群中每个实例(EC2实例)上的容器代理向Amazon ECS发送有关实例当前运行任务和资源使用情况的信息,并在接收到来自Amazon ECS的请求时启动和停止任务。有关更多信息,请参见Amazon ECS容器代理。一旦设置好,每个创建的容器实例(任何EC2机器/节点)都将是Amazon ECS的群集中的一个实例。
有关更多信息,请阅读本文档中的第10步:启动亚马逊ECS容器实例:
Choose an AMI for your container instance. You can choose the Amazon ECS-optimized AMI, or another operating system, such as CoreOS or Ubuntu. If you do not choose the Amazon ECS-optimized AMI, you need to follow the procedures in Installing the Amazon ECS Container Agent. 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. #!/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. Note For more information about this configuration, see Storing Container Instance Configuration in Amazon S3. #!/bin/bash yum install -y aws-cli aws s3 cp s3://your_bucket_name/ecs.config /etc/ecs/ecs.config
为了进一步澄清—您可以在没有ECS的情况下在单个EC2实例上创建容器。安装任何容器化技术,例如Docker,并运行create container命令,将您的EC2设置为Docker主机,并拥有尽可能多的Docker容器(或者您的EC2资源允许的数量)。
简单地说,ECS是一个经理,而EC2实例就像员工。 该经理(ECS)下的所有员工(EC2)都能执行“Docker”任务,该经理也很了解“Docker”。因此,无论何时您需要“docker”资源,您都可以出现在Manager面前。经理已经拥有每个员工(EC2)的地位,决定谁应该执行任务。
现在,回到你的问题,一个没有“员工”的经理是没有意义的,但绝对是可能的。
简单地说,弹性容器服务(ECS)是一种Docker容器编排服务。
你可以让它运行一个或多个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. The Cluster Agent would schedule the containers on the EC2 server. 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. 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.
2017年11月左右,AWS增加了ECS Fargate。现在,集群可以“无服务器”运行,无需提供EC2节点。您只需定义任务或服务操作所需的CPU和内存数量,这意味着您只需支付CPU和内存时间,而不是EC2。
好的,如你所知,EC2是AWS上的虚拟机,ECS是AWS上的容器编排系统。
要使用ECS,您需要将容器运行到一些虚拟机中,EC2是提供该功能的选项之一。
您需要在EC2上安装ECS -agent,以便与ECS建立连接。ECS还可以监视EC2上的资源使用情况。所以基本上你可以选择更高级的EC2类型,然后你的容器可以使用更多的资源(CPU/MEM)。
ECS stands for 'Elastic Container Service'. It is a container orchestration service. Lets say you have a Docker container running and you decide to update the Docker image. 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. With AWS ECS you can have this control. You specify if update is required provide the latest image id and ECS will handle the stop, pull and run etc. commands for you. It also provides with much more additional features, refer - https://aws.amazon.com/ecs/features/ EC2 stand for 'Elastic Compute Cloud'. In simple terms its a virtual machine. ECS uses EC2 to run your containers. 'These running docker containers (tasks) are run on EC2 instances'.
ECS是一个容器编配器,就像Kubernetes或Docker swarm, EC2是一个用于创建虚拟机的Amazon弹性计算云平台。ECS允许您在无服务器环境(Fargate)上运行容器,无需运行任何VM,也可以在非托管环境中运行容器,在EC2实例上托管容器。