Tuần 5 - Ngày 2: Containers (ECS, EKS, Fargate)
Mục tiêu học tập
- Hiểu architecture của ECS và EKS
- Nắm vững Fargate vs EC2 launch types
- Biết cách design container architectures
1. Container Services Overview
2. ECS Architecture
Components
EC2 vs Fargate Launch Type
| Feature | EC2 | Fargate |
|---|---|---|
| Server management | You manage | AWS manages |
| Pricing | Per EC2 instance | Per vCPU/memory/second |
| Scaling | ASG + Capacity Provider | Automatic |
| GPU support | Yes | No |
| Spot pricing | Via EC2 Spot | Fargate Spot |
| Persistent storage | EBS | EFS only |
3. EKS Architecture
Components
EKS Add-ons
- CoreDNS
- kube-proxy
- Amazon VPC CNI
- AWS Load Balancer Controller
- EBS CSI Driver
- EFS CSI Driver
4. Service Discovery & Mesh
AWS Cloud Map
AWS App Mesh
Service Mesh for:
- Traffic routing
- Observability (X-Ray integration)
- mTLS between services
- Circuit breakers
- Retries
Components:
- Virtual Nodes
- Virtual Routers
- Virtual Services
- Envoy proxy (sidecar)
Lưu ý 2026: AWS đã announce App Mesh end-of-support cuối 2026. Workload mới nên dùng VPC Lattice (managed) hoặc Istio/Linkerd self-managed.
Amazon VPC Lattice (GA 2023)
Managed application networking cho service-to-service traffic — thay thế use case của App Mesh cho microservices cross-account/cross-VPC.
Khi nào dùng VPC Lattice (vs alternatives):
| Use case | Lattice | App Mesh | ALB/NLB + PrivateLink |
|---|---|---|---|
| Cross-account service mesh, IAM-based auth | ✓ best | Phức tạp | Khả thi nhưng tốn cấu hình |
| Sidecar-free (no Envoy injection) | ✓ | ✗ (Envoy) | ✓ |
| Layer 7 routing với weighted target | ✓ | ✓ | ALB only |
| EKS service-to-service trong cluster | OK | ✓ (legacy) | ✗ |
| Cần circuit breaker, mTLS pinned | Hạn chế | ✓ | ✗ |
| Single-VPC traffic internal | ALB tốt hơn | OK | ALB tốt hơn |
Exam keyword:
- "Cross-account service communication với least operational overhead" → VPC Lattice
- "Centralized auth + observability cho microservices spread across multiple VPCs" → VPC Lattice
- "Existing App Mesh in production" → vẫn dùng (Lattice migration path), nhưng workload mới chọn Lattice.
5. Container Security
IAM Roles
Task Role:
- Permissions for containers in task
- Access AWS services (S3, DynamoDB, etc.)
Task Execution Role:
- Permissions for ECS agent
- Pull images from ECR
- Send logs to CloudWatch
- Retrieve secrets
Secrets Management
Options:
1. Secrets Manager
- Automatic rotation
- Cross-account sharing
2. Parameter Store
- Simple secrets
- Lower cost
3. Environment variables (not recommended for secrets)
Integration:
{
"secrets": [{
"name": "DB_PASSWORD",
"valueFrom": "arn:aws:secretsmanager:region:account:secret:name"
}]
}
6. Câu hỏi ôn tập
-
ECS Task Definition chứa những gì?
Xem đáp án
Task Definition là blueprint cho container(s): (1) Container definitions (image URI, CPU/memory, port mappings, env vars, secrets, log config), (2) Launch type (Fargate/EC2) và network mode (awsvpc cho Fargate), (3) CPU và Memory allocation cho task, (4) Task Execution Role (ECS agent permissions), (5) Task Role (app code permissions), (6) Volumes, health check, stop timeout. Versioned — tạo revision mới khi thay đổi.
-
Fargate vs EC2 launch type khác nhau như thế nào?
Xem đáp án
Fargate: serverless compute — không quản lý EC2, pay per task vCPU+GB, tự scale, không cần ECS agent, mỗi task có ENI riêng (awsvpc only). EC2 launch type: bạn quản lý EC2 cluster (patch OS, scale cluster, ECS Agent), pay for EC2 even when idle, có thể dùng Spot, GPU instances. Fargate tốt cho variable workloads, new services; EC2 cho steady workload, cost optimization với large clusters, hoặc GPU needs.
-
EKS Managed Node Groups là gì?
Xem đáp án
EKS Managed Node Groups là AWS-managed EC2 nodes cho EKS cluster — AWS tự động provision, configure, và upgrade worker nodes. Tự động apply Kubernetes version upgrades khi cluster upgrade. Giảm operational overhead so với self-managed nodes. Hỗ trợ Spot Instances và On-Demand. Khác EKS Fargate Profiles (fully serverless, không manage nodes). Managed Node Groups là middle ground: có node visibility nhưng AWS handle lifecycle.
-
AWS Cloud Map dùng để làm gì?
Xem đáp án
Service Discovery cho microservices — register services với name và attributes, clients discover qua DNS hoặc API calls. ECS tích hợp sẵn với Cloud Map: khi task start → tự register, khi task stop → tự deregister. Clients lookup
service.namespaceđể get healthy endpoints. Hỗ trợ health check integration. Thay thế cho Consul, Eureka trong AWS-native environments. Phù hợp cho ECS, EKS, Lambda, EC2 microservices. -
Task Role khác Task Execution Role như thế nào?
Xem đáp án
Task Execution Role: permissions cho ECS agent (infrastructure side) — pull image từ ECR, write logs đến CloudWatch, get secrets từ Secrets Manager/Parameter Store khi task start. Task Role: permissions cho application code trong container — AWS API calls mà app cần lúc runtime (S3 read, DynamoDB write, SQS send...). Least privilege: Task Role chỉ có quyền app cần, không có quyền infrastructure. Cả hai là IAM Roles riêng biệt.
Tài liệu tham khảo chính thức
Ngày tiếp theo: Lambda & Serverless