Sử dụng AWS Fargate triển khai container

Deploy the container using AWS Fargate

Deploy the container using AWS Fargate

  1. Bước đầu, chúng ta sẽ tạo Task definitions để chạy monolith
  • Truy cập ECS
  • Chọn Task definitions
  • Tìm Task definition có tên Monolith-Definition-STACK_NAME

Deploy the container using AWS Fargate

  1. Truy cập vào ECR
  • Sao chép Image URI

Deploy the container using AWS Fargate

  1. Quay lại giao diện ECS
  • Chọn Monolith-Definition-STACK_NAME

Deploy the container using AWS Fargate

  1. Trong giao diện Monolith-Definition-STACK_NAME revision 1. Chúng ta sẽ thực hiện tạo một revision mới.
  • Chọn Create new revision

Deploy the container using AWS Fargate

  1. Chọn hệ điều hành, lượng bộ nhớ và CPU

    Deploy the container using AWS Fargate

  2. Tiến hành cấu hình Container

    • Name, nhập tên service mà bạn chọn(Trong bài lab, nhập monolith-service)
    • Dán Image URI đã sao chép vào Image URI

    Deploy the container using AWS Fargate

  3. Cấu hình Log collection

    • Tìm tên log group của lab trong CloudFormation stack, sao chép physical ID và dán vào giá trị của khóa awslogs-group

    Deploy the container using AWS Fargate Deploy the container using AWS Fargate

  4. Hoàn thành tạo new revision

    Deploy the container using AWS Fargate

  5. Trong giao diện điều khiển Monolith-Definition-STACK_NAME:

  • Chọn Deploy
  • Chọn Run task

Deploy the container using AWS Fargate

  1. Trong phần Task details
  • Desired chọn 1

Deploy the container using AWS Fargate

  1. Trong giao diện Environment
  • Phần Existing cluster, chọn Cluster-STACK_NAME
  • Chọn Launch type
  • Trong Launch type, chọn FARGATE
  • Platform version chọn LATEST

Deploy the container using AWS Fargate

  1. Tiến hành cấu hình mạng ở mục Networking
  • VPC, chọn Mysfits-VPC-STACK_NAME
  • Subnets chọn Mysfits-PublicOne-STACK_NAME
  • Chọn Security Group, Chọn Use an existing security group
  • Security group name, chọn default nhưng phải cấu hình inbound cổng 80
  • Auto-assign public IP - “ENABLED”
  • Chọn Deploy

Deploy the container using AWS Fargate

  1. Tạo task thành công

Deploy the container using AWS Fargate

  1. Chọn task vừa tạo và cuộn xuống để tìm Public IP.
  • Mục đích sử dụng Public IP để sử dụng lệnh curl kiểm tra bằng cách thực hiện GET request.
  • Khi sử dụng kiểu khởi tạo Fargate, mỗi task sẽ nhận ENI và Public IP và Private IP của riêng nó.

Deploy the container using AWS Fargate

  1. Thực hiện truy cập bằng trình duyệt
http://TASK_PUBLIC_IP_ADDRESS/mysfits

Deploy the container using AWS Fargate

  1. Thực hiện lệnh curl trên giao diện dòng lệnh của IDE
curl http://TASK_PUBLIC_IP_ADDRESS/mysfits

Deploy the container using AWS Fargate

  1. Chọn task vừa tạo và chọn Logs

Deploy the container using AWS Fargate

  1. Sử dụng AWS CloudWatch để xem Log events

    Deploy the container using AWS Fargate

    • Chọn một log stream để xem chi tiết các sự kiện được log

    Deploy the container using AWS Fargate

    Deploy the container using AWS Fargate

  2. Sau khi chạy lệnh curl thành công ta có thể xóa task

  • Chọn Task
  • Chọn Monolith-Definition-STACK_NAME revision 2 (trong ảnh là 3 vì đã từng tạo fail nên tăng revision, các bạn làm đúng thì sẽ là revision 2).
  • Chọn Stop
  • Chọn Stop selected

Deploy the container using AWS Fargate

  1. Nếu được hỏi, nhấn nút Stop.

Deploy the container using AWS Fargate

  1. Xóa task thành công.

Deploy the container using AWS Fargate