Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS ECS fargate

AWS ECS fargate

- Tổng quan về AWS ECS fargate
- Một số lỗi thường gặp khi phát triển và vận hành trên AWS ECS fargate

thanhgit

May 04, 2022
Tweet

More Decks by thanhgit

Other Decks in Technology

Transcript

  1. Tổng quan ECS Fargate
    cho developer
    Thạnh Nguyễn

    View Slide

  2. 1. Sơ đồ tổng quan
    - Inbound: api gateway, ALB
    - Outbound: internet gateway
    - Trong một ECS cluster gồm có:
    - 1 ECS cluster name
    - Nhiều ECS service
    - Mỗi ECS service có 1 ECS task definition
    - Task thường được quản lý bởi ECS service
    theo cấu hình từ ECS task definition
    - Ví dụ: có thể tăng giảm số task bởi tăng
    giảm thông số desiredCount trong task
    definition, hoặc thêm các biến môi trường
    thông qua task definition, ...

    View Slide

  3. Khái niệm cơ bản
    - ECS fargate: Là một dịch vụ của AWS để quản lý containers có tính
    scale cao và nhanh trong nền tảng serverless
    - ECS cluster: là thành phần nhóm các service cùng logic để dễ quản

    - ECS service: giúp định nghĩa bao nhiêu task nên được chạy (scale
    out/in) và chúng sẽ chạy như thế nào (scaling strategy). Có khả
    năng liên kết với load balancer
    - ECS task definition là metadata kể cho ECS cách chạy docker
    container (định dạng json)
    - ECR: là một private docker image repository của AWS tương tự
    docker hub

    View Slide

  4. Xử lý một số trường hợp ở mức developer
    - Khi một lỗi logic xảy ra có thể xem lỗi tại sentry, datadog,
    elasticsearch, ... và xem logs tại ECS tasks hoặc cloudwatch
    - Revert version khi code deploy trên ECS bị lỗi -> có thể đánh tag để
    revert hoặc thay đổi task definition đến version trước đó
    - Lỗi không tìm thấy route khi gọi từ aws api gateway -> có thể api
    gateway chưa add route -> thêm route vào api gateway -> deploy
    stage (nếu stage không tự động deploy)
    - Muốn migrate database với một command khác thì chạy một
    container tương tự với command khác (chức năng run task)
    - Muốn thêm/xóa/sửa biến môi trường thì tạo một task definition mới
    sau đó apply vào ECS service
    - Nếu lỗi liên quan network thì có thể do security group hoặc WAF, ...

    View Slide

  5. Xử lý một số trường hợp ở mức cao hơn
    - Nếu NLB chỉ route tới 1 ECS task có thể NLB chưa bật tính năng cross-
    zone LB
    - Nếu có dùng private link cho private ECS cluster thì chú ý tới tính
    năng cross-zone LB của NLB vì mỗi liên kết private link chỉ tạo kết nối
    trên cùng AZ
    - Chú ý tới task level resources (Memory và CPU) và container
    level resources trong cấu hình ECS để tối ưu chi phí sử dụng
    - Khi muốn dùng chức năng readonlyRootFilesystem trong ECS fargate
    mà muốn có một số directory có thể rw được thì nên tạo mount points
    khi build image và dùng mountPoints trong ECS definition, do trên
    ECS fargate không dùng được chức năng tmpfs mounts:

    View Slide

  6. Q&A
    docker run --name=tmp \
    --volume=app_tmp:/app/tmp:rw \
    --volume=/app/tmp \
    ...
    --entrypoint /bin/bash \
    --workdir=/app image-name:local -c 'build-commands'
    hoặc xem thêm tại: https://toris.io/2021/06/using-ecs-exec-with-readonlyrootfilesystem-
    enabled-containers/

    View Slide

  7. Xem logs tại task trong ECS service

    View Slide

  8. Xem logs tại cloudwatch

    View Slide

  9. Refs
    https://docs.aws.amazon.com/AmazonECS/latest/userguide/update-
    service-console-v2.html
    https://aws.amazon.com/blogs/compute/tag/amazon-ecs/
    https://docs.aws.amazon.com/AmazonECS/latest/developerguide/trouble
    shooting.html
    https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_ru
    n_task.html
    https://www.youtube.com/watch?v=o7s-eigrMAI

    View Slide