Skip to content

Latest commit

 

History

History

05-docker-app-ecs

Container Games on Amazon ECS

  • Containerized four web-based games using Docker with an Nginx-optimized base image, ensuring compatibility with AWS Fargate on the Linux x86_64 architecture.
  • Pushed the Docker images to Amazon Elastic Container Registry (ECR) for secure and scalable image management.
  • Deployed the containerized games on Amazon Elastic Container Service (ECS), ensuring seamless operation in a cloud-native environment.
  • Implemented auto-scaling and load balancing to handle varying traffic loads efficiently and maintain high availability.
  • Explored blue-green deployment strategies by manually deploying a new updated service, enhancing deployment practices for minimizing downtime and risks.
  • Services : AWS ECS, ECR, ALB, Docker, Nginx
ECS GUIDE

Key Components of Amazon ECS

Introduction to Amazon ECS

  • Amazon Elastic Container Service (ECS) is a fully managed container orchestration service provided by AWS that makes it easy to deploy, manage, and scale containerized applications.
  • ECS supports Docker containers and allows you to run and manage containers on a cluster of EC2 instances or using AWS Fargate, a serverless compute engine.
  1. Clusters:
  • A logical grouping of container instances or tasks.
  • Clusters can run on EC2 instances, AWS Fargate, or a mix of both.
  1. Task Definitions:
  • Blueprint for your application.
  • Specifies parameters for the container, such as Docker image, CPU, memory, port mappings, and environment variables.
  • Defines multiple containers within a single task if needed.
  1. Tasks and Services:
  • Tasks: A running instance of a task definition. It is the smallest unit of work in ECS.
  • Services: Maintain the desired number of task instances. Can be associated with load balancers to distribute traffic across tasks.
  1. Container Instances:
  • EC2 instances registered to the ECS cluster.
  • Run the ECS agent, which manages the tasks.
  1. ECS Agent:
  • A container running on each container instance that communicates with the ECS control plane to manage tasks.
  1. Launch Types:
  • EC2 Launch Type: Deploys tasks on a cluster of Amazon EC2 instances managed by the user.
  • Fargate Launch Type: Deploys tasks on serverless infrastructure managed by AWS, removing the need to manage EC2 instances.
  1. Task Scheduler:
  • Places tasks based on the specified placement strategy and constraints.
  • Ensures the desired state of tasks is maintained in the cluster.
  1. Load Balancing:
  • Integrates with Elastic Load Balancing (ELB) to distribute incoming traffic across tasks.
  • Supports Application Load Balancer (ALB) and Network Load Balancer (NLB).
Docker Commands used in this mini project
$ docker build -t <image> .       # build
$ docker images                   # display build images
$ docker run -d -p 80:80 <image>  # run container
$ docker ps                       # display running containers
$ docker ps -a                    # display all/stopped  containers
$ docker stop <container-id>      # stop running container
$ docker rm <container-id>        # delete running container
$ docker rmi <image>              # delete image

Architecture

arch-game-ecs


Output

Screenshots

proj-5-5-rusult-home-page

Demo - Video : LINK

Cluster - Service
proj-5-5a-ecs-cluster-services
Cluster - Task
proj-5-5b-ecs-cluster-tasks
ALB
proj-5-5c-alb
Blue Green Deployment
video demo
https://github.com/user-attachments/assets/97be68ad-b16a-4d88-a24c-88756a5e0216
changes
proj-5-6a-blue-green-deploy
Force Deploy
proj-5-6b
Updating Cluster
proj-5-6c
proj-5-6d
Result Updated
proj-5-6e-result-changed
Screenshots @ loacalhost:80 | Distroless Nginx
Docker Build
proj-5-0a-local-docker-build
Docker Run
proj-5-0b-local-docker-run
Result
proj-5-0c-result
proj-5-0d-local-docker-app

Troubleshooting

  1. Tried with Distroless Image : So ecs health check fails, due to absence of shell and curl in distroless nginx image Solution : Used Alpine Image

  2. Architecture Problem : Mismatch Container of differenet architecture : amd64, arm64 can cause problem

    • Explanation :
      • My laptop's local builds resulted in arch:ARM containers (As I am Using MacBook Air M1).
      • And I selected Fargate as Arch: x86_64 ~ amd64. So containers were running and exiting.
      • So, have to troubleshoot in CloudWatch > Logs > exec failed
      • Solution: Build Multi-arch image or specify with --from arch explicitly
      • NOTE: On Fargate arm64, my image works, but i have used x86_64 in ECS Cluster setup.
WHY used x86_64 or amd64 ???
proj-0-note
I am using Region : us-east !! for safe side