Here’s twtech detailed guide on Amazon ECS – Fargate Launch Type, the serverless way to run
containers on AWS.
The concept: Amazon
ECS with Fargate Launch Type
Fargate is a serverless compute engine for containers that lets twtech run Docker containers without managing EC2 instances. AWS handles
provisioning, scaling, and infrastructure management.
twtech defines and run tasks; AWS provisions resources behind the scenes.
Fargate Architecture (ECS + Fargate)
# pgsql
+---------------------------+
| ECS Cluster |
| (Serverless) |
+-------------+-------------+
|
▼
+----------------------------+
|
Task Definition |
|
- Container image |
|
- CPU & Memory config |
+-------------+--------------+
|
▼
+----------------------------+
|
ECS Task (Fargate) |
| Runs on AWS infra |
| Load Balancing |
| Auto-scaled |
+ ----------------------------+
Key Concepts in Fargate
Concept |
Description |
ECS Cluster. |
Logical grouping; no EC2s in
Fargate. |
Task Definition. |
Blueprint for containers: image,
ports, CPU/mem. |
Task. |
A running container (or group). |
Service. |
Maintains desired task count and
manages restarts. |
Fargate Profile. |
Not required (used in EKS
Fargate). |
✅
Benefits of ECS with Fargate
Advantage |
Description |
No servers to manage. |
AWS provisions compute behind the
scenes. |
Auto scaling. |
Task-based scaling via ECS Service
Auto Scaling. |
Secure by default. |
Runs tasks in isolated compute
environments. |
Pay-as-you-go. |
Billed per second for vCPU and
memory. |
Integrated with IAM. |
Fine-grained access control. |
❌
Limitations
Limitation |
Notes |
Limited OS control. |
twtech can't SSH or install custom
OS agents. |
Fewer custom networking options. |
Compared to EC2. |
Limited volume support. |
Only EFS and ephemeral storage. |
Steps to Run Containers Using Fargate
- Push Docker Image to Amazon ECR
- Create a Task Definition
- Select Fargate as the launch type
- Define CPU, memory, image, ports, and IAM role
- Create ECS Service
- Choose Fargate launch
- Set number of tasks, VPC, subnets, and security groups
- Deploy and Monitor
- ECS Console or CLI
- Logs via CloudWatch
Example Task Definition (Fargate)
# json
{
"family": "twtech-fargate-app",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "256",
"memory": "512",
"containerDefinitions": [
{
"name": "twtechspringapp",
"image": "devopspatemf2021/twtech:twtech-spring-boot-mongo",
"essential": true,
"portMappings": [
{
"containerPort": 8080,
"protocol": "tcp"
}
]
}
]
}
Note: awsvpc networking mode is required for Fargate.
ECS Fargate vs EC2 Launch Type
Feature |
ECS
+ EC2 |
ECS
+ Fargate |
Infra Management. |
twtech manages EC2. |
Fully managed |
Startup Speed. |
Slower (EC2 boot). |
Faster |
Cost Model. |
EC2 per-hour. |
Per-task (CPU/RAM/second) |
OS Customization. |
Full. |
Limited |
Use Cases. |
Custom agents, long-living VMs. |
Simple apps, microservices |
twtech Best Use Cases for ECS Fargate
- Microservices and REST APIs
- Scheduled batch jobs
- Event-driven applications
- Short-lived container tasks
- Teams who don't want to manage infrastructure.
Project: Hands-on
How twtech deploys Amazon ECS cluster for its Applications, and integrate with the Load Balanceer(ALB), Auto Scaling Group(ASG), CloudWatch, CloudFormation and other
Resources.
Search for service: ECS
Link
of how it works:
Let’s Get started with: twtechecscluster
Create a cluster: twtech-ecs-cluster
Create
cluster
An Amazon ECS cluster groups together tasks, and services, and
allows for shared capacity and common configurations. All of your tasks,
services, and capacity must belong to a cluster.
Cluter
name: : twtech-ecs-cluster
Infrastructure – optional
Serverless
(aws provides the compute infrastructure)
twtech cluster is automatically configured for AWS Fargate (serverless)
with two capacity providers. Add Amazon EC2 instances.
Network settings for Amazon EC2 instances:
By default Amazon EC2 instances are launched in the default
subnets for your default VPC. To use the non-default VPC, specify the VPC and
subnets.
Monitoring - optional
CloudWatch Container Insights is a monitoring and
troubleshooting solution for containerized applications and microservices.
Monitoring - optional
CloudWatch Container Insights is a monitoring and
troubleshooting solution for containerized applications and microservices.
Deployment of cluster in progress: twtechecscluster
Namespace: twtechecscluster
To, a Successful cluster
creation: twtechecscluster
Verify
the Autoscaling group created from EC2 console: infra-ECS-Cluster-twtechecscluster
More
datails of the ASG and how twtech May choose to: Edit the configurations.
Verify the stacks created on: CloudFormation
CloudFormation may use JSON or YAML templates to define and automate the creation,
update, and deletion of resources in an AWS account. This allows for
consistent and repeatable deployments, version control, and simplifies
infrastructure management.
Stacks info: infra-ECS-Cluster-twtechecscluster
Stacks
Events: infra-ECS-Cluster-twtechecscluster
Stacks
Resources: infra-ECS-Cluster-twtechecscluster
Stacks
Output: infra-ECS-Cluster-twtechecscluster
Stacks
Parameters: infra-ECS-Cluster-twtechecscluster
Stacks
Template: infra-ECS-Cluster-twtechecscluster
Details
of ECS-cluster: twtechecscluster
twtech may need to edit ASG in the EC2 console to configure
and register instances into ECS Cluster:
twtechecscluster.
Select the cluster and click open: twtechecscluster
Edit
the number of Instances from : Capacity overview
From:
To edit the : Desired capacity
Save changes by clicking on: update
Alternatively: Or
From:
To:
Scroll down and update changes to save new configuration: update
From: upgrading
To:
Verify that the instances been registered to the cluster(twtechecscluster) are : Running
Verify that instances has been registered into the cluster: twtechecscluster
Alternatively: Or
Namespace for cluster: twtechecscluster
Details about services in the namespace: twtechecscluster
How
twtech may update ECS Settings for: twtechecscluster
How twtech creates Task
definition in the ECS cluster (twtechecscluster): twtech-task-def
Create new task definition: twtech-tasks-def
Task definition configuration
Task
definition family , Specify a unique task
definition family name.
Infrastructure requirements
Specify the infrastructure requirements for the task definition.
NB:
ECS Task-Execution-Role is auto-generated by: AWS-ECS service.
Container – 1
Container (application) image: devopspatemf2021/twtech:twtech-spring-boot-mongo
Environment
variables - optional
Deploy the task definition: twtech-task-def
Details of containers from task-definition: twtech-task-def
Details of json file from task-definition: twtech-task-def
How twtech uses the task definition created (twtechwebapps-task-def) for services exposure of its applications: twtech-ecs-td-svc
Next,
twtech needs to exposure the application (devopspatemf2021/twtech:twtech-spring-boot-mongo)
wih a service(SVC): twtechspringapp-ecs-td-svc
Select task definition created: twech-task-def
Assign a service name (it is okay to use the auto-assigned name) : twtechspringapp-task-def-service-8ys7ml4b
Environment: AWS Farget
Existing
cluster
Deployment configuration: Scheduling strategy
Networking
Create a security group Inbound rules: allow port8080
from IPV4 everywhere
Load balancing - optional
Configure load balancing using Amazon Elastic Load Balancing to
distribute traffic evenly across the healthy tasks in your service
Load balancer name, assign a unique name for the load balancer.: twtech-ecs-alb
Provisioning
service exposure for: devopspatemf2021/twtech:twtech-spring-boot-mongo
From: Service deployment in progress
To, It may take a couple of minutes to provision Resources: successful
How twtech gets more details
on the health
check and Metric for the service: twtechspringapp-task-def-service-8ys7ml4b
How to get the
IPaddress of the container running in the cluster:twtechspringapp
Go to EC2 console , navigate
on the menu and click open: Target Groups
How twtech access the application on the browser via: Load balance DNS
Go to EC2 console ,
navigate on the menu and click open: Load
Balancers
Form the selected application load balancer created copy the DSN
(Doman Name Service): twtechspringapp-ecs-alb-3018xxxx.us-east-2.elb.amazonaws.com
Try several browsers: google chrome
NB:
Some browsers are not compatible
Try several browsers: Firefox Mozilla
Other Resouces provision include, the Load balancer: twtch-ecs-alb
Resouces created security group: ecs-sg
Resouces created target group: twtech-ecs-tg
Resouces created CloudFormation: twtech-task-def-service
From: CREATE_IN_PROGRESS
To: CREATE_COMPLETE
Tasks running in the cluster:
- twtechspringapp
- twtechspringapp-svc
Clicking on each task, we can give more details: configuration
Clicking on each task, we can give more details: Logs
Clicking on each task we can give more details: Network
Clicking on each task, we can give more details: Tags
Clicking on each service we can give more details: Events
Other details: Resoource map
Monitoring: ALB
Monitoring: Target group
Health check settings: Edit
How twech scale-out(increases) or Scale-in(reduces) tasks by re-configuring the service: Edit
Go to cluster, then select the service to: update configuration.
scale-out from: 1
To: 5
replicas
Scroll down to Save changes: update
Number of tasks and IPaddres increase: 5 each
NB:
With the application load balancer attached to the
cluster: traffic is evenly distributed to all the
applications.
No comments:
Post a Comment