Day 48 : ECS


What is ECS ?
ECS (Elastic Container Service) is a fully-managed container orchestration service provided by Amazon Web Services (AWS). It allows you to run and manage Docker containers on a cluster of virtual machines (EC2 instances) without having to manage the underlying infrastructure.
With ECS, you can easily deploy, manage, and scale your containerized applications using the AWS Management Console, the AWS CLI, or the API. ECS supports both "Fargate" and "EC2 launch types", which means you can run your containers on AWS-managed infrastructure or your own EC2 instances.
ECS also integrates with other AWS services, such as Elastic Load Balancing, Auto Scaling, and Amazon VPC, allowing you to build scalable and highly available applications. Additionally, ECS has support for Docker Compose and Kubernetes, making it easy to adopt existing container workflows.
Overall, ECS is a powerful and flexible container orchestration service that can help simplify the deployment and management of containerized applications in AWS.
Difference between EKS and ECS ?
EKS (Elastic Kubernetes Service) and ECS (Elastic Container Service) are both container orchestration platforms provided by Amazon Web Services (AWS). While both platforms allow you to run containerized applications in the AWS cloud, there are some differences between the two.
Architecture: ECS is based on a centralized architecture, where there is a control plane that manages the scheduling of containers on EC2 instances. On the other hand, EKS is based on a distributed architecture, where the Kubernetes control plane is distributed across multiple EC2 instances.
Kubernetes Support: EKS is a fully managed Kubernetes service, meaning that it supports Kubernetes natively and allows you to run your Kubernetes workloads on AWS without having to manage the Kubernetes control plane. ECS, on the other hand, has its own orchestration engine and does not support Kubernetes natively.
Scaling: EKS is designed to automatically scale your Kubernetes cluster based on demand, whereas ECS requires you to configure scaling policies for your tasks and services.
Flexibility: EKS provides more flexibility than ECS in terms of container orchestration, as it allows you to customize and configure Kubernetes to meet your specific requirements. ECS is more restrictive in terms of the options available for container orchestration.
Community: Kubernetes has a large and active open-source community, which means that EKS benefits from a wide range of community-driven development and support. ECS, on the other hand, has a smaller community and is largely driven by AWS itself.
In summary, EKS is a good choice if you want to use Kubernetes to manage your containerized workloads on AWS, while ECS is a good choice if you want a simpler, more managed platform for running your containerized applications.
Task :
Set up ECS (Elastic Container Service) by setting up Nginx on ECS
Build docker image for nginx and push it to ecr
Log into ec2 instance and install docker. Create a docker file for nginx and build docker image.
Push the docker image to ecr. This can be done by attaching IAM role with permission to push and pull image to ecr.
Setup ECS Cluster
- Log in to your AWS Management Console and navigate to the ECS dashboard.
- Click on “Clusters” in the left sidebar and then click the “Create Cluster” button. Choose the cluster type that suits your needs (e.g., EC2 or Fargate).
- Configure the cluster settings as per your requirements. Follow the on-screen instructions to create the ECS cluster.
Define a Task Definition
In the ECS dashboard, click on “Task Definitions” in the left sidebar and then click the “Create new Task Definition” button.
Choose the launch type compatibility that matches your cluster (EC2 or Fargate).
Configure the task definition details:
Name: Enter a name for your task definition.
Task Role: If required, specify an IAM role.
Network mode: Choose the appropriate mode for your application.
Task Execution IAM Role: Specify an IAM role for task execution.
In the “Container Definitions” section, click “Add container” and configure the container settings:
Container name: Enter a name for your container. Image: Specify the URL of the Nginx Docker image you built or pushed earlier. Port mappings: Map port 80 on the container to a port on the host (usually 80).
Click “Add” to add the container definition, and then click “Create” to create the task definition.
Create an ECS Service
In the ECS dashboard, click on “Clusters” and select the cluster you created earlier.
Click on the “Create” button next to “Services.”
Choose the launch type compatibility that matches your cluster (EC2 or Fargate).
Configure the service details:
Launch type: Choose your desired launch type.
Task definition: Select the task definition you created earlier.
Service name: Enter a name for your ECS service.
Number of tasks: Set the desired number of tasks to run.
Configure your network settings and load balancer (if required).
Review and create the service.
Access Nginx on ECS
Once the ECS service is running, you can access Nginx through the public IP or DNS of your ECS instances or through an Application Load Balancer if you configured one.
Remember to set up security groups and VPC configurations to allow inbound traffic to the appropriate ports.
Subscribe to my newsletter
Read articles from Rahul Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
