An Ecs Cluster is nothing but a grouping of Tasks, services and Ec2 Instances. It can be taught from a logical group of Ec2 instances that host application containers. Ecs clusters are region specific which means the whole cluster should be in one Aws region.
Ecs Cluster can be of two modes :
Ec2 ( Linux/Windows ) + networking : this will have Ec2 instances running for hosting the container with networking available by default which means we will launch these ec2 instances inside a VPC.
Networking : in this mode we will have only a VPC available. Launching the containers on Hosts are taken care of by the Aws itself. This mode is used with Fargate launch type where aws will take care of launching the ec2 instances to host the containers. This can be taught as Ecs serverless launch.
Container Instance IAM role :
When we launch a Ec2 instance in an Ecs, it contains an Ecs agent which will talk to the Ecs cluster service all the time for sending details of the running containers and also getting details from Ecs Cluster service. In order for the Ecs agent inside a Ec2 instance to talk to the cluster service an specific role needs to be assigned to the Ec2 instance. The role is called “AmazonEC2ContainerServiceforEC2Role”.
Create Cluster ->
As we already discussed, we can see the 2 modes Ec2(linux + windows ) + networking and only networking. We will go with the Ec2 Linux + networking. Once we choose this, aws will take care of creating the instances for us using the Ecs optimized ami , vpc , subnets and also an auto scaling group. This autoscaling group will be used when we require to increase our instances in the cluster.
We have an Option to create an empty cluster also from the console.We have 2 provisioning models, on-demand and spot. We will go with the on-demand model.
We can choose instance type from the list box. I will go with the “t2.micro” but it depends on your application workload.
Number of instances are 2. The ami to create the Ec2 instance is also provided by the aws itself. We can choose the ami from the list box whether it can be Amazon Linux 2 or Amazon Linux 1.
Ebs storage is 30GB by default which means we can't choose less than this. Choose the keypair to login to the ec2 instances once created.
In the network section, we can ask Aws to create a vpc , subnet and all other necessary details. We either ask aws or give our own vpc and subnet details. I will choose my default vpc and also use a security group that I created. The security group is open to all
The Next is the Container Instance IAM role. This is the same IAM role that we discussed earlier. When we launch a Ec2 instance in an Ecs, it contains an Ecs agent which will talk to the Ecs cluster service all the time for sending details of the running containers and also getting details from Ecs Cluster service. In order for the Ecs agent inside a Ec2 instance to talk to the cluster service an specific role needs to be assigned to the Ec2 instance. The role is called “AmazonEC2ContainerServiceforEC2Role”. We can create a role with the specific permissions assigned or we can ask aws to create one for us which I will be doing here.
We can see that aws uses CloudFormation templates to launch the Ecs Cluster. We can see the details once the cluster is created as below,
If we check the stack, we can see that launch configuration, auto scaling groups are created. Once the Running of the templates are done, we can see that the Cluster is created.
We can see there is nothing running. The cluster is active but we don't see any things running even the Ec2 instances.
Since there are no tasks available to run, hence the ec2 instances are not running. Once we run the tasks we can see the ec2 instances running. But if we go to the Ec2 instance console and we can see Ec2 instances running and available. Similarly we can also see the launch configurations and auto scaling group.
In the next article, we will see the basics of Task Definition and understand its components.
No comments :
Post a Comment