Scope:
- Intro,
- The concept: Amazon ECS with Fargate Launch Type,
- Fargate Architecture (ECS + Fargate),
- Key Concepts in Fargate,
- Benefits of ECS with Fargate,
- Limitations,
- Steps to Run Containers Using Fargate,
- Sample Task Definition (Fargate),
- ECS Fargate vs EC2 Launch Type,
- Best Use Cases for ECS Fargate,
- Project: Hands-on
Intro:
- Here’s twtech overview on Amazon ECS using 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 then provisions resources behind the scenes.
Fargate Architecture (ECS + Fargate)
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
Sample 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"
}
]
}
]
}
NB:
- 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
- other
Resources.
Step-1:
Search for AWS service: ECSLink
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 twtech tasks, services, and capacity must belong to a cluster.
Infrastructure – optional
- Serverless
(aws provides the compute infrastructure)
- twtech cluster is automatically configured for AWS Fargate (serverless)
with two capacity providers.
NB:
- twtech may also Add Amazon EC2 instances (If need be).
Network settings for Amazon EC2 instances:
- By default, Amazon EC2 instances are launched in the default subnets for twtech default VPC.
- To use the non-default VPC, twtech needs to specify the twtech-VPC and twtech-subnets.
Monitoring - optional
- CloudWatch Container Insights is a monitoring and troubleshooting solution for containerized applications and microservices.
Step-2:
- Deployment of cluster in progress: twtechecscluster
- Namespace: twtechecscluster
- Creation in prgress
To:
- A Successful cluster
creation: twtechecscluster
Step-3:
- twtech Verifies 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.
Step-4:
- twtech 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
Step-5:
twtech edits ASG in the EC2 console to configure and register instances into ECS Cluster: twtechecscluster.
- Select the cluster and click open: twtechecscluster
Step-6:
twtech Edits the number of Instances from : Capacity overview
From:
To edit the : Desired capacity
- Save changes by clicking on: update
- Alternatively:
From:
To:
- Scroll down and update changes to save new configuration: update
- From: upgrading
To:
Step-7:
twtech Verifies that the instances been registered to the cluster (twtechecscluster) are: Running
Step-8:
- twtech Verifies that instances has been registered into the cluster: twtechecscluster
Alternatively:
- Namespace for cluster: twtechecscluster
Step-9:
- twtech accesses the Details about services in the namespace: twtechecscluster
Step-10:
- twtech may update ECS Settings for: twtechecscluster
Step-11:
- How twtech creates Task
definition in the ECS cluster (twtechecscluster): twtech-task-def
twtech Creates new task definition: twtech-tasks-def
- Task definition configuration
- Task definition family , twtech Specifies a unique task definition family name.
Infrastructure requirements
- twtech Specifies the infrastructure requirements for the task definition.
- ECS Task-Execution-Role is auto-generated by: AWS-ECS service.
Step-11:
Container – 1
- twtech defines the abosulute path to twtech Container (application) image in GitHub: devopspatemf2021/twtech:twtech-spring-boot-mongo
Step-12:
Environment
variables - optional
- twtech sets environmental veriable (optional)
Step-13:
- twtech Deploys 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
Step-14:
- 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
Step-15:
- twtech Selects task definition created: twech-task-def
- twtech Assigns a service name (it is okay to use the auto-assigned name) like: twtechspringapp-task-def-service-8ys7mxxx
Environment: AWS Farget
- Existing cluster
- Deployment configuration: Scheduling
strategy
- Networking
- twtech Creates a security group Inbound rules: allow port8080
from IPV4 everywhere
Step-17:
Load balancing - optional
- twtech Configures load balancing using Amazon Elastic Load Balancing to distribute traffic evenly across the healthy tasks in its service
- Load balancer name, assign a unique name for the load balancer.: twtech-ecs-alb
Step-18:
twtech Provisions 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
Step-19:
- twtech gets more details
on the health
check and Metric for the service: twtechspringapp-task-def-service-8ys7ml4b
Step-20:
- twtech gets the
IPaddress of the container running in the cluster:twtechspringapp
- Go to EC2 console , navigate
on the menu and click open: Target Groups
Step-21:
- twtech accesses the application on the browser via: Load balance DNS
- twtech Goes to EC2 console, and navigate to : Load
Balancers
Step-22:
- Form the selected application load balancer created copy the DSN
(Doman Name Service): twtechspringapp-ecs-alb-3018xxxx.us-east-2.elb.amazonaws.com
- twtech may need to Try several browsers: google chrome
- Some browsers are not compatible
- Try several browsers: Firefox Mozilla
- twtech has successfully:
- created an EC2 cluster using farget luanch type,
- added its application that is hosted in ECR,
- configured for Auto-scaling,
- only requiped port opened on the inboud rule for the application,
- Provisioned the service discovery and its application is running seamlessly in the serverlesss infra.
NB:
- Below, are Other Resouces provisioned like 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
Step-23:
- How twech scale-out (increases) or Scale-in(reduces) tasks by re-configuring the service: Edit
- twtech Goes 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
- With the application load balancer attached to the cluster: traffic is evenly distributed to all the applications.
No comments:
Post a Comment