Sub topic 5
Choosing Where Pods Run
This chapter assumes you have read the chapters on how EKS is put together and on creating a cluster with eksctl. You should know what a pod, a node, and a Deployment are, and you should be able to read an eksctl ClusterConfig.
The EKS control plane never runs your pods. Pods run on compute that you attach to the cluster. EKS offers three options: managed node groups, AWS Fargate, and self-managed nodes. They differ in who patches the operating system, how pods are isolated, and how much you can customize.
The Three Compute Options
| Option | What AWS manages | What you manage | Pod isolation |
|---|---|---|---|
| Managed node groups | EC2 provisioning, Auto Scaling group, node draining on updates | AMI choice, instance types, capacity limits | Pods share the node |
| Fargate | The compute, the OS, and patching | Pod resource requests, Fargate profiles | One pod per micro-VM |
| Self-managed nodes | Nothing beyond the control plane | Everything: AMI, Auto Scaling group, upgrades, draining | Pods share the node |
Managed Node Groups
A managed node group is a set of EC2 instances that EKS creates and updates for you. Behind it sits an EC2 Auto Scaling group. EKS launches the instances with an EKS-optimized AMI, registers them with the cluster, and labels them.
The config from the cluster creation chapter defines one:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
managedNodeGroups:
- name: ng-1
instanceType: m5.large
desiredCapacity: 2
minSize: 1
maxSize: 4The three capacity fields behave like this:
desiredCapacityis the node count at creation time.minSizeandmaxSizebound what the Auto Scaling group may do. Nothing scales the group on its own. A tool such as Cluster Autoscaler or Karpenter, covered in the autoscaling chapter, has to change the desired count.- Changing
desiredCapacitylater is a manual scale operation, for example witheksctl scale nodegroup.
Updates and draining
When you update a node group to a new AMI or Kubernetes version, EKS launches new nodes, cordons old ones, and drains them. Draining respects PodDisruptionBudgets. A budget that allows zero disruptions can stall an update, so check budgets before you upgrade.
Spot and On-Demand capacity
A managed node group uses one capacity type. Set spot: true in eksctl to use Spot Instances, which cost less but can be reclaimed with two minutes of notice. Give a Spot group several instance types so the Auto Scaling group can find capacity in more pools:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
managedNodeGroups:
- name: ng-spot
instanceTypes: ["m5.large", "m5a.large", "m4.large"]
spot: true
minSize: 0
maxSize: 6
desiredCapacity: 2
labels:
capacity: spotKeep a baseline On-Demand group for workloads that cannot tolerate interruption, and put interruption-tolerant pods on the Spot group.
Fargate
Fargate runs each pod in its own isolated micro-VM. There are no nodes for you to patch or scale. Which pods go to Fargate is decided by a Fargate profile. A profile holds a namespace and optional label selectors. A pod that matches a profile at creation time is scheduled onto Fargate.
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
fargateProfiles:
- name: fp-batch
selectors:
- namespace: batch
labels:
compute: fargateFargate has limits that matter in practice:
- It does not support DaemonSets, because there is no shared node to run them on. Logging and monitoring agents must be sidecars or use a platform integration.
- Pods cannot run privileged containers or use
hostNetworkorhostPort. - It does not support GPUs.
- Pods cannot mount EBS volumes. Use EFS for shared persistent storage.
- Each pod is billed for the vCPU and memory it requests, rounded up to a supported size. Pod requests therefore drive the bill directly.
- Pods start more slowly than on a warm node, because a micro-VM must be provisioned.
Pods on Fargate need pod execution permissions and a private subnet. Fargate profiles accept only private subnets, so your VPC needs private subnets with a route to a NAT gateway or suitable VPC endpoints for image pulls.
Self-Managed Nodes
With self-managed nodes you create the Auto Scaling group and launch template yourself, or have eksctl create them with nodeGroups. You choose the AMI, user data, and bootstrap settings. You are responsible for patching, replacing, and draining nodes during upgrades.
Choose this option when you need something managed node groups do not allow. Examples are a custom AMI with a non-standard OS configuration, or an instance setup that the managed group API does not expose. Many of these cases are now covered by managed node groups with a custom launch template, so check that first.
Steering Pods to the Right Nodes
Once you have several node groups, you control placement with Kubernetes scheduling features. EKS sets labels on managed nodes, such as eks.amazonaws.com/nodegroup and eks.amazonaws.com/capacityType (values ON_DEMAND or SPOT).
This Deployment requires Spot capacity using a node selector:
apiVersion: apps/v1
kind: Deployment
metadata:
name: worker
spec:
replicas: 3
selector:
matchLabels:
app: worker
template:
metadata:
labels:
app: worker
spec:
nodeSelector:
eks.amazonaws.com/capacityType: SPOT
containers:
- name: worker
image: nginx:stable
resources:
requests:
cpu: 250m
memory: 256MiUse taints on specialized nodes, such as GPU nodes, and tolerations on the pods that should use them. A node selector attracts pods to nodes. A taint repels pods that do not tolerate it. Use both together to reserve a node group for one workload.
To see where pods landed:
kubectl get nodes -L eks.amazonaws.com/nodegroup,eks.amazonaws.com/capacityType
kubectl get pods -o widePod Density Limits
With the Amazon VPC CNI, each pod gets a VPC IP address, so the number of pods per node is bounded by the instance type. The limit comes from the number of network interfaces and the IPs each can hold. An m5.large supports 29 pods by default. Small instances can run out of pod slots long before they run out of CPU or memory. Pods then stay Pending with an event about insufficient pods or IPs.
Two common fixes:
- Use larger instance types, which have more network interfaces and addresses.
- Enable prefix delegation in the VPC CNI, which assigns /28 IPv4 prefixes to interfaces and raises the pod limit per node considerably.
Common Errors
- Pods Pending with
Insufficient cpuorToo many pods. The node group is full. RaisemaxSizeand make sure an autoscaler is running, or use larger instances. - Node group update hangs. A PodDisruptionBudget blocks draining. Relax the budget or scale the workload up first.
- Pod did not go to Fargate. The pod's namespace or labels did not match the profile when the pod was created. Existing pods are not moved, so restart them after you create a profile.
- Fargate pod fails to start. Check that the profile's subnets are private and can pull the image.
- Spot pods vanish. A Spot interruption reclaimed the node. Run more than one replica and spread them across nodes and zones.
Summary of Trade-offs
- Pick managed node groups as the default. You get EC2 flexibility with automated updates.
- Pick Fargate when you want no node operations and per-pod isolation, and you can live with its limits.
- Pick self-managed nodes only when a managed group cannot express what you need, and accept the operational work.
Exercise
A team runs a logging agent as a DaemonSet and wants to move their whole cluster to Fargate to stop managing nodes. What problem will they hit, and what is one way to handle it?
Show answer
Fargate does not support DaemonSets, because pods do not share a node. The agent will not run on Fargate pods. They can run the agent as a sidecar container in each pod, use a Fargate-supported logging integration, or keep a managed node group for workloads that need DaemonSets.
Exercise
Your Spot node group has minSize 0, maxSize 6, and desiredCapacity 2. Load increases and pods stay Pending, yet the group stays at 2 nodes. Why, and what do you add?
Show answer
The group's size is only bounded by minSize and maxSize. Nothing changes the desired count by itself. You need a node autoscaler such as Cluster Autoscaler or Karpenter to raise the desired capacity when pods are unschedulable.
Exercise
You create a Fargate profile for the namespace batch, but existing pods in that namespace still run on EC2 nodes. How do you fix this?
Show answer
Profiles are evaluated only when a pod is created. Restart the pods, for example with kubectl rollout restart deployment/<name> -n batch, so the replacement pods match the profile and are scheduled onto Fargate.