Amazon EKS — Fargate — Practice Exercises
Chapter 6 — Practice Exercises
Exercise 1: Fargate vs EC2 Decision
Question: You’re running a Kubernetes CronJob that processes data every hour for 15 minutes, using 1 vCPU and 2 GB memory. Compare the monthly cost on Fargate vs a dedicated t3.medium EC2 node.
Show Solution
Fargate cost:
Runtime: 15 min/hr × 24 hrs × 30 days = 10,800 min = 180 hours
Cost: (1 × $0.04048 + 2 × $0.004445) × 180 = $0.04937 × 180 = $8.89/month
EC2 (t3.medium, 24/7):
Cost: $0.0416/hr × 730 hrs = $30.37/month
Fargate is ~71% cheaper because you only pay for the 180 hours the job actually runs, not the 730 hours the EC2 node sits idle.
Exercise 2: Fargate Profile Design
Question: Design Fargate profiles for: production web app (should NOT go to Fargate), batch jobs (should go to Fargate), and dev environment (should go to Fargate).
Show Solution
fargateProfiles:
- name: batch
selectors:
- namespace: batch
labels:
compute: fargate
- name: dev
selectors:
- namespace: dev
# Production web app — NO Fargate profile
# It runs in the 'production' namespace
# No matching profile = scheduled on EC2 nodes
Key insight: Fargate is opt-in. Only pods matching a profile run on Fargate. The production web app stays on EC2 because no profile matches the production namespace.
Exercise 3: DaemonSet Alternative
Question: You need to collect logs from all pods using Fluent Bit. On EC2 nodes, you’d use a DaemonSet. How do you achieve this on Fargate?
Show Solution
Use Fargate’s built-in log router or sidecar containers:
Option 1: Fargate built-in log router (FireLens):
apiVersion: v1
kind: Pod
metadata:
annotations:
eks.amazonaws.com/logging: enabled
spec:
containers:
- name: app
image: my-app:latest
Option 2: Sidecar container:
spec:
containers:
- name: app
image: my-app:latest
volumeMounts:
- name: shared-logs
mountPath: /var/log/app
- name: fluent-bit
image: fluent/fluent-bit:latest
volumeMounts:
- name: shared-logs
mountPath: /var/log/app
readOnly: true
volumes:
- name: shared-logs
emptyDir: {}
Exercise 4: Fargate Limitations
Question: Your team wants to run a PostgreSQL database on EKS with persistent EBS storage and a monitoring DaemonSet. Can this run on Fargate? If not, what’s the alternative?
Show Solution
No, this cannot run on Fargate. Two blockers:
- No EBS volumes — Fargate doesn’t support EBS. PostgreSQL needs persistent block storage.
- No DaemonSets — Monitoring agents can’t run as DaemonSets on Fargate.
Alternative: Mixed mode
- Run PostgreSQL on an EC2 managed node group with EBS storage
- Run monitoring as a DaemonSet on EC2 nodes
- Run stateless application pods on Fargate
Exercise 5: Cost Optimization
Question: Your Fargate bill is $500/month for 20 pods running 24/7 at 1 vCPU, 2 GB each. How can you reduce costs?
Show Solution
Current Fargate cost:
20 pods × $0.04937/hr × 730 hrs = $720.82/month
(My estimate: $36/pod × 20 = ~$720)
Option 1: Switch steady workloads to EC2
3× m5.large (fit ~10 pods each) = 3 × $70 = $210/month
EKS cluster fee (already paying): $73
Total: ~$283/month (61% savings)
Option 2: Use Spot EC2 nodes
3× m5.large Spot = 3 × $25 = $75/month
Total: ~$148/month (79% savings)
Option 3: Fargate Savings Plans (1-year commit)
Up to 50% discount on Fargate
New cost: ~$360/month
Recommendation: Move 24/7 steady workloads to EC2 Spot. Keep Fargate only for bursty/intermittent workloads.
What’s Next?
On to networking: Chapter 7 — Networking.