Containers on AWS
ECS, EKS, Fargate and ECR compared, with task networking, IAM roles, placement, scaling and the private-subnet endpoints that image pulls need.
Exam tasks: 2.5 (choose compute and container platforms), 4.3 and 4.4 (modernize to containers), 3.3
The decision: do you need Kubernetes specifically, and do you want to manage the instances that run the containers? Those two answers pick between ECS, EKS, Fargate and EC2 capacity.
Choosing the platform
| ECS | EKS | Fargate | Lambda | |
|---|---|---|---|---|
| What it is | AWS-native orchestrator | Managed Kubernetes control plane | Serverless capacity for ECS or EKS | Functions |
| Pick it when | You want the simplest AWS-native container service | Kubernetes tooling or portability is required | You do not want to manage instances | Short, event-driven work |
| You manage | Tasks, and instances unless Fargate | Pods, and nodes unless Fargate or Auto Mode | Task definitions only | Code |
| Runs on-premises | ECS Anywhere | EKS Anywhere and hybrid nodes | No | No |
| Limits | AWS only | Kubernetes expertise | No GPUs, no privileged containers, no host network | 15 minutes |
Exam signal
"Portable, existing Kubernetes manifests, Helm charts" means EKS. "Run containers with the least operational effort" means ECS or EKS on Fargate. "Need GPUs, DaemonSets or custom AMIs" means EC2 capacity, managed by EKS Auto Mode or Karpenter if you want less work.
ECS building blocks
| Term | Meaning |
|---|---|
| Task definition | The blueprint: images, CPU and memory, ports, roles, log driver and secrets |
| Task | One running instance of a task definition, for a batch job or a one-off run |
| Service | Keeps a desired number of tasks running, replaces failed ones and registers them with a load balancer |
| Cluster | The logical group of capacity |
| Capacity provider | Links a cluster to an Auto Scaling group, Fargate or Fargate Spot |
- A service uses the replica strategy (a number of tasks) or daemon (one per instance, EC2 only).
- Placement strategies apply on EC2 capacity:
spreadacross an attribute such as AZ,binpackto pack tight and save instances, andrandom. Constraints such asdistinctInstancekeep tasks apart. Fargate spreads across AZs and ignores these. - Rolling updates use
minimumHealthyPercentandmaximumPercent. The deployment circuit breaker stops and rolls back a deployment whose tasks keep failing to start. - Service auto scaling adds tasks by target tracking on CPU, memory or ALB requests per target. Capacity provider managed scaling adds instances when tasks cannot be placed.
- Service Connect and Cloud Map give services stable names. See compute and containers.
ECS networking, roles and capacity
Network modes
| Mode | How it works | Use it when | Limits |
|---|---|---|---|
| awsvpc | Each task gets its own ENI and private IP | You want per-task security groups and VPC flow logs per task. Required on Fargate | ENIs per instance limit density; turn on ENI trunking |
| bridge | Docker's virtual bridge on the host; container ports map to host ports | EC2 launch type, many tasks per host with dynamic host ports behind an ALB | Security groups apply to the host, not the task |
| host | Containers share the host's network directly | Maximum network performance | Two tasks can't use the same port on one host |
| none | No external networking | Batch jobs that need no network | No connectivity at all |
Per-task security groups
Only awsvpc gives each task its own security group. In bridge or host mode, every task on an instance shares the instance's security groups, so you can't isolate one service's traffic from another on the same host.
IAM roles
- Task execution role: used by the ECS agent to pull images from ECR, write logs to CloudWatch and fetch secrets from Secrets Manager or Parameter Store for the task definition.
- Task role: used by your application code to call AWS APIs (read S3, write DynamoDB). Give each task definition its own least-privilege role.
- Container instance role (EC2 launch type only): lets the agent register the instance with the cluster. Don't give application permissions here, because every task on the host could use them.
On EKS, the equivalent of a task role is EKS Pod Identity or IAM roles for service accounts (IRSA).
Capacity
- Capacity providers attach Auto Scaling groups or Fargate and Fargate Spot to a cluster, with weights and a base, so a service can run a baseline on Fargate and burst onto Fargate Spot.
- Fargate Spot suits interruption-tolerant tasks and gives a two-minute warning before reclaiming capacity.
- EKS Auto Mode and Karpenter manage EKS worker nodes for you when Fargate's limits (no GPUs, no DaemonSets) rule it out.
Fargate
- You choose a CPU and memory combination for the task. AWS runs it on isolated capacity, and each task has its own kernel boundary.
- Every task uses
awsvpc, so give each its own security group and keep tasks in private subnets with the endpoints below. - Fargate Spot (ECS) is discounted and interruptible, with a two-minute warning. Run it for stateless, retryable work.
- Not supported: GPUs, privileged mode, host networking and DaemonSets-style one-per-node workloads.
- Charges are per vCPU-second and GB-second from image pull to task stop.
EKS
| Topic | What to know |
|---|---|
| Control plane | Managed, spread across three AZs, with the API server behind a load balancer. You never see the control plane instances |
| Nodes | Managed node groups, self-managed nodes, Fargate profiles, or EKS Auto Mode which also manages the node lifecycle |
| Pod networking | The VPC CNI gives each pod a VPC IP address, so large clusters can exhaust subnet IPs. Fix with prefix delegation, custom networking or IPv6 |
| Ingress | The AWS Load Balancer Controller creates ALBs for Ingress and NLBs for Services |
| Pod permissions | EKS Pod Identity or IRSA. Never put application permissions on the node role |
| Cluster access | Access entries map IAM principals to Kubernetes permissions, replacing the old aws-auth ConfigMap |
| Scaling | HPA for pods, and Karpenter or Cluster Autoscaler for nodes |
| Versions | A Kubernetes version gets standard support for a limited period, then extended support at an added cost |
Running out of pod IPs
A cluster that cannot start new pods while nodes have free CPU and memory is often out of subnet IP addresses, because the VPC CNI assigns a VPC IP to every pod. The fix is more address space for pods, not bigger nodes.
Amazon ECR
- Private registries per account and Region, with image scanning (basic, or enhanced through Amazon Inspector), lifecycle policies to expire old images, immutable tags and encryption with KMS.
- Replication copies repositories across Regions and accounts, and a pull-through cache mirrors upstream public registries.
- Tasks in private subnets with no NAT need the
ecr.apiandecr.dkrinterface endpoints, the S3 gateway endpoint (image layers come from S3) and a CloudWatch Logs endpoint if the tasks log there.
Pulls fail in a private subnet
Two ECR interface endpoints are not enough. The image layers are stored in S3, so without the S3 gateway endpoint, or a NAT, the pull stalls after the manifest download.
Scenarios
Private pulls need the ECR API and Docker registry endpoints, plus S3 because image layers are stored there. A public IP does not work in a private subnet without an internet gateway route. Pulling is done by the task execution role, so the task role is irrelevant. Fargate supports only awsvpc.
EKS keeps the Kubernetes API and tooling, so the charts continue to work, while AWS runs the control plane, and managed node groups or Auto Mode handle node patching. Rewriting for ECS changes the process the team wants to keep. Lambda would require a redesign, and kubeadm leaves the control plane and nodes to the team.
Related
- Compute and containers: the decision tree, Beanstalk, service discovery and mesh.
- Load balancers: ALB and NLB in front of tasks and pods.
- VPC endpoints: the endpoints private image pulls depend on.
Further reading
AWS Lambda
Invocation models, event source mappings, concurrency, versions and aliases, VPC networking, packaging and the limits the exam asks about.
Hybrid and edge compute
Choosing between Outposts racks, Outposts servers, Local Zones and Wavelength Zones when a workload must run close to users, devices or a data center.