Amazon ECS - Elastic Container Service

Amazon ECS - Elastic Container Service

·

6 min read

This blog will discuss ECS - Elastic Container Service by AWS. Let's jump into it.

ECS

ECS or Amazon Elastic Container Service is a highly scalable container orchestration service provided by Amazon Web Services. It allows you to run and manage Docker containers on a cluster of EC2 instances or using AWS Fargate, a serverless compute engine for containers.

Amazon ECS Layers:


Diagram showing the capacity, controller, and provisioning layers.

  • Capacity - The infrastructure where your containers run

  • Controller - Deploy and manage your applications that run on the containers

  • Provisioning - The tools that you can use to interface with the scheduler to deploy and manage your applications and containers

ECS Application Lifecycle


Diagram showing the capacity, controller, and provisioning layers.

The application lifecycle in Amazon ECS (Elastic Container Service) involves the management of tasks and services throughout their lifecycle.

  1. Task Definition Creation: The application lifecycle starts with creating a task definition. A task definition is a blueprint that defines how containers should run within ECS.

  2. Task Scheduling: Once a task definition is created, tasks based on that definition can be scheduled on ECS container instances or as Fargate tasks.

  3. Task Execution: When a task is scheduled to run, ECS provisions the necessary resources, such as EC2 instances or Fargate resources, to host the containers.

  4. Task Monitoring: During task execution, you can monitor the health and resource utilization of tasks using Amazon CloudWatch.

  5. Task Updates: If you need to update a running task, you can create a new task definition version with the desired changes and update the service to use the new version.

  6. Scaling: ECS provides scaling capabilities to manage the number of tasks running in a service.

  7. Service Management: Services in ECS provide higher-level abstractions for managing long-running tasks.

  8. Task Termination: When a task is no longer needed or needs to be stopped, you can manually terminate the task or update the service to a desired count of zero.

Common use cases in Amazon ECS

Fargate is suitable for the following workloads:

  • Large workloads that need to be optimized for low overhead

  • Small workloads that have the occasional burst

  • Tiny workloads

  • Batch workloads

EC2 is suitable for the following workloads:

  • Workloads that require consistently high CPU core and memory usage

  • Large workloads that need to be optimized for price

  • Your applications need to access persistent storage

  • You must directly manage your infrastructure

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.

Difference between EKS and ECS

FeatureEKSECS
ArchitectureDistributed architecture. The Kubernetes control plane is distributed across multiple EC2 instances.Centralized architecture. There is a control plane that manages the scheduling of containers on EC2 instances.
Managed KubernetesYesNo
Custom orchestration engineNoYes
AutoscalingSupports autoscaling of pods and nodes (based on demand)Supports autoscaling of pods (configure scaling policies for your tasks and services)
Deployment FlexibilityMore flexible with multi-region deployments, hybrid deployments, and custom configurationsFlexible deployment options with EC2 or Fargate launch types
Community SupportLarge and active Kubernetes communityECS has a growing community, but smaller than Kubernetes
Container CompatibilitySupports both Docker containers and other container runtimes compatible with KubernetesSupports Docker containers
NetworkingKubernetes-native networking (Kubernetes Service Discovery, Ingress, etc.)Load Balancer integration, service discovery, network modes
Monitoring and loggingSupports built-in monitoring and loggingSupports integration with CloudWatch
Control planeManaged by AWSManaged by you
Worker nodesManaged by AWSManaged by you

Task: Set up ECS (Elastic Container Service) by setting up Nginx on ECS.

Let us do this task step by step.

Set up an ECS Cluster

AWS Console > Navigate to ECS > On the left panel, click on Clusters

Create Cluster > Give Cluster name NginxCluster > Let the Networking be default > And by default Infrastructure AWS Fargate (Serverless) is selected

Click on Create.

Create a Task Definition

In the left Panel of ECS > Select Task Definitions

Click on Create new task definitions > Create new task definition

Configure task definition and containers

Task definition family: nginx-task

Under Container details:

Name: nginx-container

Image URI: public.ecr.aws/nginx/nginx:latest

You can get this Image URL from Amazon ECR Public Gallery.

Let other things be as it is and click on default.

Configure environment, storage, monitoring, and tags

I am letting the app environment by default which is AWS Fargate.

Let other default things be as it is and click on Next.

Review and create

Review the configuration and click on Create Task Definition.

Create a Service

Go to ECS > Select & open the Cluster you created.

Click on Create which is next to Services.

Let the Environment section be the default.

In the Deployment Configuration section > Select Service > Give the Service Name > Select the task definition you created.

In the Networking Tab > Let the things be default except for SG > Click on Create new SG.

Security group name: nginx-SG

Security group description: Security Group for Nginx Cluster

And configure the SG as below:

Click on Create.

Let's test by accessing the Nginx container using the Public IPv4 of Fargate.

For the IP go to the Tasks tab in the ECS Cluster dashboard > Select the Task number of your task required > You can find the Public IPv4.

This can be further done by exposing Nginx publicly, by setting up an Application Load Balancer (ALB). And then can be reached by the public IP address of your load balancer.


In this blog, I have explained ECS and set up an Nginx cluster in ECS. If you have any questions or want to share your experiences, please comment below. Don't forget to read my blogs and connect with me on LinkedIn and let's have a conversation.

To help me improve my blog and correct my mistakes, I am available on LinkedIn as Sneha K S. Do reach me and I am open to suggestions and corrections.

#Day48 #90daysofdevops

Did you find this article valuable?

Support Sneha K S by becoming a sponsor. Any amount is appreciated!