3.1.7 Container Services (ECS, EKS, ECR)

Container Services cho Developer

ECS vs EKS

FeatureECSEKS
OrchestratorAWS proprietaryKubernetes
Learning curveThấpCao
PortabilityAWS onlyMulti-cloud, on-premises
Launch typesFargate, EC2Fargate, EC2, Outposts
Service meshApp MeshApp Mesh, Istio
LoggingCloudWatch (native)CloudWatch, Fluentd, Fluent Bit
Exam focusCao (task definitions, services)Thấp (high-level concepts)

Amazon ECS — Key Concepts

Cluster → Service → Task (running container)
              Task Definition (blueprint)
              ├── Container image (ECR)
              ├── CPU / Memory
              ├── Port mappings
              ├── Environment variables
              ├── IAM Task Role
              └── Log configuration

Launch Types

FargateEC2
Server management❌ Serverless✅ You manage
PricingPer vCPU + memory per secondEC2 instance cost
ScalingTask-levelInstance + task level
GPU support
Best forMost workloadsGPU, specific instance types

ECS + CodeDeploy (Blue/Green)

# appspec.yaml cho ECS Blue/Green
version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "arn:aws:ecs:us-east-1:123:task-definition/my-app:2"
        LoadBalancerInfo:
          ContainerName: "my-app"
          ContainerPort: 8080

Amazon EKS — Key Concepts

EKS Cluster → Node Group → Pods (running containers)
               ├── Managed Node Group (EC2)
               ├── Self-managed Nodes (EC2)
               └── Fargate Profile (serverless)

EKS cho Developer

ConceptMô tả
PodSmallest deployable unit (1+ containers)
DeploymentManages ReplicaSets, rolling updates
ServiceStable network endpoint cho Pods
ConfigMapConfiguration data (non-sensitive)
SecretSensitive data (base64 encoded)
IngressHTTP/HTTPS routing (ALB Ingress Controller)

EKS + AWS Integration

AWS ServiceEKS Integration
IAMIAM Roles for Service Accounts (IRSA)
ALBAWS Load Balancer Controller
CloudWatchContainer Insights, Fluent Bit
X-RaySidecar daemon container
Secrets ManagerCSI Secrets Store Driver
EFSEFS CSI Driver
ECRPull images natively

Health Checks (EKS)

# Kubernetes deployment with health checks
livenessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 15
  periodSeconds: 10
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 5
  • Liveness probe: Restart container nếu unhealthy
  • Readiness probe: Remove từ service nếu not ready

Amazon ECR — Container Registry

FeatureMô tả
Image scanningBasic (on push) + Enhanced (Inspector)
Lifecycle policiesAuto-delete old/untagged images
Cross-region replicationReplicate images across regions
Immutable tagsPrevent image tag overwrite
Pull-through cacheCache public registry images
# Lifecycle policy — keep only last 10 images
aws ecr put-lifecycle-policy --repository-name my-app \
  --lifecycle-policy-text '{
    "rules": [{
      "rulePriority": 1,
      "selection": {
        "tagStatus": "any",
        "countType": "imageCountMoreThan",
        "countNumber": 10
      },
      "action": {"type": "expire"}
    }]
  }'

Exam Tip: ECS = AWS-native, simpler. EKS = Kubernetes, portable. Fargate = serverless cho cả ECS và EKS. ECR lifecycle policies để manage image storage. ECS Task Role = container-level IAM permissions. EKS IRSA = pod-level IAM permissions.