Two ways to run containers on AWS. ECS is the AWS-native scheduler; EKS is managed Kubernetes. Fargate turns either into "no EC2 to babysit".
Hai cách chạy container trên AWS. ECS là scheduler AWS-native; EKS là Kubernetes managed. Fargate biến cả hai thành "không cần lo EC2".
Pick ECS whenChọn ECS khi
Team is AWS-native, no k8s historyTeam AWS-native, chưa quen k8s
You want the simplest scheduler + deep AWS integrationMuốn scheduler đơn giản nhất + tích hợp AWS sâu
Fargate-only, zero infraChỉ Fargate, zero infra
Pick EKS whenChọn EKS khi
You already run Kubernetes on-prem / another cloudĐang chạy k8s on-prem hoặc cloud khác
You need cloud-agnostic manifests / HelmCần manifest / Helm cloud-agnostic
Ecosystem tooling matters more than AWS-native flowCần hệ sinh thái k8s hơn flow AWS-native
ECS building blocksKhối lego của ECS
ClusterLogical pool of EC2 (or Fargate) capacityNhóm capacity EC2 (hoặc Fargate) logic
Service"Keep N tasks running, register in ALB""Giữ N task chạy, đăng ký ALB"
Task DefinitionJSON: image · CPU · RAM · env · portsJSON: image · CPU · RAM · env · port
TaskOne running instance of a Task DefMột instance đang chạy của Task Def
IAM — the three rolesIAM — ba roleEC2 Instance Profile = the ECS agent on the host (register with cluster). Task Execution Role = ECS launching the task (pull ECR image, push logs, read secrets to inject) — required on Fargate. Task Role = the actual application (call S3, DynamoDB…). None inherits from another.EC2 Instance Profile = agent ECS trên host (đăng ký cluster). Task Execution Role = ECS khởi chạy task (pull image ECR, đẩy log, đọc secret để inject) — bắt buộc trên Fargate. Task Role = application (gọi S3, DynamoDB…). Không role nào kế thừa role nào.
Networking modesChế độ networking
Mode
BehaviourCách hoạt động
Where usedDùng ở
none
No network, no port mappingKhông mạng, không port mapping
Sidecar-onlyChỉ sidecar
bridge
Docker virtual net (default EC2)Docker virtual net (mặc định EC2)
ECS EC2
host
Bypass Docker net · uses host NICBỏ Docker net · dùng NIC host
ECS EC2
awsvpc
Task = own ENI + private IP · SG per taskTask = ENI + IP riêng · SG per task
Fargate defaultMặc định Fargate
ALB + ECS = dynamic port mappingALB + ECS = dynamic port mapping
Task Def declares a container port; ECS registers each task to a random host port; ALB finds them via target-group registration.Task Def khai port container; ECS đăng ký mỗi task với host port ngẫu nhiên; ALB tìm qua target-group.
Run many replicas of the same image on one EC2 host without port conflicts.Chạy nhiều replica cùng image trên 1 EC2 mà không đụng port.
Enables rolling updates — old tasks drain from the TG, new ones register.Cho phép rolling update — task cũ drain khỏi TG, task mới đăng ký vào.
bridge mode (EC2 launch type) only. In awsvpc/Fargate each task's ENI registers the container port as an ip target — no dynamic host ports.Chỉ với bridge mode (EC2 launch type). Với awsvpc/Fargate, ENI của mỗi task đăng ký container port làm ip target — không có dynamic host port.
East-west traffic → ECS Service Connect (built-in Envoy + Cloud Map namespace, retries, telemetry). App Mesh reaches end of support 30 Sep 2026 — no longer an answer.Traffic service-to-service → ECS Service Connect (Envoy built-in + Cloud Map namespace, retry, telemetry). App Mesh hết hỗ trợ 30/09/2026 — không còn là đáp án.
ScalingScaling
ECS Service Auto Scaling scales tasks. That's different from the ASG that scales the EC2 hosts underneath.ECS Service Auto Scaling scale task. Khác với ASG scale EC2 hosts phía dưới.
Self-Managed NodesYou build the AMI & ASGBạn tự dựng AMI & ASG
FargateNo nodes to babysit · per-pod capacityKhông node phải chăm · capacity per-pod
EKS Auto ModeEKS provisions/patches/scales nodes for you (Karpenter-based) · fee on top of EC2EKS tự provision/patch/scale node (dựa Karpenter) · phí thêm trên EC2
Data volumes for EKSData volume cho EKSDeclare a StorageClass that points at a CSI driver: EBS · EFS (works with Fargate) · FSx Lustre · FSx NetApp ONTAP.Khai StorageClass trỏ tới CSI driver: EBS · EFS (hỗ trợ Fargate) · FSx Lustre · FSx NetApp ONTAP.
Pod IAM & versionsIAM cho pod & versionPer-pod IAM = EKS Pod Identity (simpler, newer) or IRSA (OIDC-based) — never node instance roles. K8s versions: 14 mo standard support, then 12 mo extended at ~6× cluster fee ($0.10 → $0.60/hr) — upgrade or pay.IAM per-pod = EKS Pod Identity (đơn giản, mới hơn) hoặc IRSA (dựa OIDC) — không dùng instance role của node. Version K8s: 14 tháng standard, sau đó 12 tháng extended với phí cluster ~6× ($0.10 → $0.60/giờ) — upgrade hoặc trả tiền.
Secrets & envSecrets & env
Inject secrets/config as env vars via SSM Parameter Store or Secrets Manager. The Task Execution Role needs read permission — injection happens at launch, not by the app.Chèn secret/config vào env bằng SSM Parameter Store hoặc Secrets Manager. Task Execution Role cần quyền đọc — inject lúc launch, không phải do app.
Don't bake secrets into the container image — reference an ARN in the Task Def instead.Đừng nhúng secret vào image — tham chiếu ARN trong Task Def.