Amazon EKS — Mixed Mode (EC2 + Fargate)

1 minute read

Mixed Mode: EC2 + Fargate

Most production EKS clusters use a hybrid approach — EC2 nodes for steady workloads and Fargate for bursty or serverless workloads.


Architecture

Mixed Mode EKS Cluster
┌─────────────────────────────────────────────────────┐
│                                                     │
│  EC2 Managed Node Group                             │
│  ┌────────────┐ ┌────────────┐ ┌────────────┐     │
│  │   Node 1   │ │   Node 2   │ │   Node 3   │     │
│  │ ┌──┐ ┌──┐  │ │ ┌──┐ ┌──┐  │ │ ┌──┐ ┌──┐  │     │
│  │ │P1│ │P2│  │ │ │P3│ │P4│  │ │ │P5│ │P6│  │     │
│  │ └──┘ └──┘  │ │ └──┘ └──┘  │ │ └──┘ └──┘  │     │
│  └────────────┘ └────────────┘ └────────────┘     │
│  → Steady workloads (web, APIs, databases)          │
│                                                     │
│  Fargate                                            │
│  ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐              │
│  │ Job1 │ │ Job2 │ │ Job3 │ │ Job4 │              │
│  └──────┘ └──────┘ └──────┘ └──────┘              │
│  → Batch jobs, cron, dev workloads                  │
│                                                     │
└─────────────────────────────────────────────────────┘

Config Example

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: mixed-cluster
  region: us-east-1

managedNodeGroups:
  - name: general
    instanceType: m5.large
    desiredCapacity: 3
    labels:
      compute: ec2

fargateProfiles:
  - name: batch
    selectors:
      - namespace: batch
      - namespace: jobs

Routing Pods to the Right Compute

Use namespace selectors or node selectors to control placement:

# This pod runs on EC2 (no Fargate profile for 'production' namespace)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: production
spec:
  replicas: 3
  template:
    spec:
      containers:
        - name: web
          image: nginx

---
# This pod runs on Fargate (matches 'batch' namespace profile)
apiVersion: batch/v1
kind: Job
metadata:
  name: process-data
  namespace: batch
spec:
  template:
    spec:
      containers:
        - name: worker
          image: my-worker:latest

Best Practices

  1. EC2 for steady workloads — Web servers, APIs, databases
  2. Fargate for ephemeral workloads — Batch jobs, cron, CI/CD runners
  3. Separate namespaces — Makes Fargate profile matching clean
  4. Don’t put everything on Fargate — Cost adds up for 24/7 workloads

What’s Next?

Practice: Fargate Exercises.