Table of contents
- ECS
- Amazon ECS Layers:
- ECS Application Lifecycle
- Common use cases in Amazon ECS
- Difference between EKS and ECS
- Task: Set up ECS (Elastic Container Service) by setting up Nginx on ECS.
- Set up an ECS Cluster
- Create a Task Definition
- Configure task definition and containers
- Configure environment, storage, monitoring, and tags
- Review and create
- Create a Service
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:
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
The application lifecycle in Amazon ECS (Elastic Container Service) involves the management of tasks and services throughout their lifecycle.
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.
Task Scheduling: Once a task definition is created, tasks based on that definition can be scheduled on ECS container instances or as Fargate tasks.
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.
Task Monitoring: During task execution, you can monitor the health and resource utilization of tasks using Amazon CloudWatch.
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.
Scaling: ECS provides scaling capabilities to manage the number of tasks running in a service.
Service Management: Services in ECS provide higher-level abstractions for managing long-running tasks.
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
Architecture:
EKS (Elastic Kubernetes Service):
Distributed architecture: The Kubernetes control plane is distributed across multiple EC2 instances.
ECS (Elastic Container Service):
Centralized architecture: There is a control plane that manages the scheduling of containers on EC2 instances.
Managed Kubernetes:
EKS:
Yes, EKS is a managed Kubernetes service.
ECS:
No, ECS is not a Kubernetes service; it has its custom orchestration engine.
Custom Orchestration Engine:
EKS:
No custom orchestration engine; it uses standard Kubernetes.
ECS:
Yes, ECS uses its custom orchestration engine.
Autoscaling:
EKS:
Supports autoscaling of pods and nodes based on demand.
ECS:
Supports autoscaling of pods. You can configure scaling policies for your tasks and services.
Deployment Flexibility:
EKS:
More flexible with multi-region deployments, hybrid deployments, and custom configurations.
ECS:
Offers flexible deployment options with EC2 or Fargate launch types.
Community Support:
EKS:
Benefits from a large and active Kubernetes community.
ECS:
Has a growing community but is smaller compared to Kubernetes.
Container Compatibility:
EKS:
Supports both Docker containers and other container runtimes compatible with Kubernetes.
ECS:
Primarily supports Docker containers.
Networking:
EKS:
Utilizes Kubernetes-native networking, including Kubernetes Service Discovery and Ingress.
ECS:
Integrates with AWS Load Balancers, offers service discovery, and supports different network modes.
Monitoring and Logging:
EKS:
Supports built-in monitoring and logging features.
ECS:
Supports integration with AWS CloudWatch for monitoring and logging.
Control Plane:
EKS:
The Kubernetes control plane is managed by AWS.
ECS:
The control plane is managed by you when using ECS.
Worker Nodes:
EKS:
Worker nodes (EC2 instances) are managed by AWS.
ECS:
Worker nodes are managed by you when using ECS.
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:mainline-apline
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.