Skip to main content

How to Run Kubernetes on Spot Instances Without Breaking Production

· 10 min read

Spot instances are the biggest single cost lever in Kubernetes. Move a workload from on-demand to spot and you save 60-90% on compute, instantly, with a one-line node selector change. Teams that get it right run 70-80% of their cluster on spot and still hit 99.95% uptime. Teams that get it wrong wake up to a cascading outage at 3am because AWS reclaimed every node in the cluster in the same five minutes.

The difference isn't luck. It's a handful of specific practices around workload classification, interruption handling, and node diversification.

What Spot Actually Is​

"Spot" means different things on different clouds, but the shape is the same everywhere: unused capacity the cloud provider sells at a discount, with the right to reclaim it on short notice.

CloudNameDiscountInterruption noticeMax runtime
AWSSpot Instances60-90%2 minutesUnlimited
GCPSpot VMs60-91%30 secondsUnlimited
GCP (old)Preemptible VMs60-91%30 seconds24 hours max
AzureSpot VMs60-90%30 secondsUnlimited

The numbers that matter for planning:

  • AWS Spot gives you 2 minutes of warning via instance metadata. Enough time for a graceful shutdown if your workload is designed for it.
  • GCP Spot gives you 30 seconds. Barely enough time to drain a pod. Assume you'll be killed without warning.
  • Azure Spot is closer to GCP in practice — 30 seconds of notice via scheduled events.

Design for 30-second interruptions. If your workload survives GCP Spot, it survives everything.

Step 1: Classify Your Workloads​

Not everything can run on spot. The decision is binary per workload, and gut feeling always gets it wrong. Use this matrix:

Workload typeSpot-safe?Why
Stateless web/API replicas (3+ pods)YesReplicas absorb interruptions, load balancer re-routes
Batch jobs with checkpointingYesRestart from last checkpoint
CI/CD runnersYesRerun failed jobs
Dev/staging environmentsYesBrief downtime is acceptable
Async workers with retry queuesYesQueue redelivers messages
ML training with checkpointsYesResume from checkpoint
Single-replica stateful appsNoNo redundancy to absorb the interruption
Databases (primary)NoData corruption risk, long recovery
Stateful apps without HANoOne eviction = outage
Anything with local storageNoLocal data is gone with the node
Long-running batch without checkpointsNoWasted work on each eviction
Ingress controllers (single replica)NoAll traffic dies
Cluster-critical system podsNocoredns, kube-proxy, CNI — don't risk these

The rule of thumb: if losing this pod right now would cause an incident, don't put it on spot.

Step 2: Set Up a Mixed Node Pool​

Don't put everything on spot. A practical cluster has three node pools:

on-demand pool      →  system pods, databases, single-replica stateful
spot pool (primary) → stateless apps, batch, CI/CD, dev
spot pool (backup) → fallback when primary instance type is unavailable

With Karpenter (recommended) or Cluster Autoscaler, define node pools that diversify across instance types and availability zones. Spot capacity is per-(instance-type, AZ) pair — if you only request m5.large in us-east-1a, you'll get evicted together when AWS reclaims that pool.

# Karpenter NodePool — spot pool with diversification
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
name: spot-general
spec:
template:
spec:
requirements:
- key: karpenter.sh/capacity-type
operator: In
values: ["spot"]
- key: node.kubernetes.io/instance-type
operator: In
# 10+ instance types across 2+ families reduces correlated eviction
values:
- m5.large
- m5.xlarge
- m5a.large
- m5a.xlarge
- m6i.large
- m6i.xlarge
- m6a.large
- m6a.xlarge
- c5.large
- c5.xlarge
- key: topology.kubernetes.io/zone
operator: In
values: ["us-east-1a", "us-east-1b", "us-east-1c"]
nodeClassRef:
name: default
taints:
- key: capacity-type
value: spot
effect: NoSchedule
limits:
cpu: "1000"
disruption:
consolidationPolicy: WhenUnderutilized
expireAfter: 720h

The NoSchedule taint is important: it forces workloads to explicitly opt in to spot with a toleration. Accidentally putting a database on spot because someone forgot a nodeSelector should not be possible.

Step 3: Opt Workloads In Explicitly​

Every spot-safe workload must declare it:

spec:
template:
spec:
tolerations:
- key: capacity-type
operator: Equal
value: spot
effect: NoSchedule
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: karpenter.sh/capacity-type
operator: In
values: ["spot"]

preferred instead of required is deliberate: if spot capacity is unavailable, the pod falls back to on-demand. You pay more for a few hours but stay up. Use required only for workloads where you'd rather have the pod pending than run on on-demand (usually: non-urgent batch).

Step 4: Spread Replicas Across Nodes​

The single biggest mistake with spot: running 3 replicas, all on the same spot node. When AWS reclaims it, all 3 die at once, and the service is down until new pods schedule elsewhere.

Topology spread constraints fix this:

spec:
template:
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: my-api
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: my-api

This forces replicas onto different nodes and prefers different zones. A single spot interruption now kills at most one replica.

Pair it with a PodDisruptionBudget so voluntary evictions (node upgrades, consolidation) don't also knock out the service:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: my-api
spec:
minAvailable: 2 # with 3 replicas, only 1 can go down at a time
selector:
matchLabels:
app: my-api

Note: PDBs don't apply to involuntary interruptions (spot reclaim). Topology spread is what saves you there.

Step 5: Handle the Interruption Signal​

AWS, GCP, and Azure all emit a signal before reclaiming a node. The signal is useless unless something is listening.

AWS Node Termination Handler (or Karpenter's built-in interruption handling) catches the 2-minute warning, cordons the node, and drains pods gracefully. Install one of them — without it, pods get killed instantly with no graceful shutdown.

# Karpenter handles this automatically via SQS interruption queue
# For Cluster Autoscaler setups, install AWS Node Termination Handler:
helm install aws-node-termination-handler \
eks/aws-node-termination-handler \
--namespace kube-system \
--set enableSpotInterruptionDraining=true \
--set enableRebalanceMonitoring=true \
--set enableScheduledEventDraining=true

On the pod side, make sure your containers handle SIGTERM gracefully:

spec:
terminationGracePeriodSeconds: 60 # must be < spot notice (120s for AWS)
containers:
- name: app
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 15 && /app/graceful-shutdown.sh"]

The sleep 15 gives the load balancer time to remove the pod from rotation before the app starts shutting down. Without it, in-flight requests get 502s for those 15 seconds.

Step 6: Monitor Interruption Rate​

Spot interruptions are normal. Excessive interruptions are a signal that your instance mix is too narrow, or that you're chasing a capacity-constrained instance type.

# Spot interruption rate over the last 24 hours
sum(rate(karpenter_interruption_actions_performed_total{action="InterruptedSpot"}[24h]))
* 86400

# Percentage of nodes that were spot-interrupted in the last 7 days
(
sum(increase(karpenter_interruption_actions_performed_total{action="InterruptedSpot"}[7d]))
/
sum(increase(karpenter_nodes_created_total[7d]))
) * 100

Healthy clusters see 1-5% interruption rate on spot nodes. 10%+ means your instance diversification is too narrow, or you're running in a capacity-starved region. Add more instance types before adding more on-demand.

Step 7: Calculate the Real Savings​

The 60-90% discount is the list-price delta. The realized savings are lower because:

  1. Spot nodes sometimes fall back to on-demand when capacity is unavailable. Budget for 5-10% fallback.
  2. Interrupted pods cause brief over-provisioning as replacement pods start before old ones fully terminate.
  3. Some workloads need a minimum on-demand floor for stability (system pods, databases). This floor isn't spot-eligible.

Real-world spot savings calculation:

On-demand cost (before):        $10,000/month
Spot eligible workloads: 70% of compute = $7,000/month
Spot discount: 70% → $2,100/month on spot
Fallback to on-demand (5%): 5% of spot * on-demand price = $350/month extra
Non-spot-eligible (unchanged): $3,000/month on-demand

Actual bill after spot: $2,100 + $350 + $3,000 = $5,450
Savings: $4,550/month = 45.5%

A 45% cluster-wide savings on a 70% spot adoption is the realistic target. If you're seeing less than 30%, your spot coverage is too narrow or your fallback rate is too high.

Tools like K8Cost surface the per-workload breakdown — how much of each namespace runs on spot, what the per-workload savings are, and which eligible workloads haven't migrated yet.

Common Mistakes​

1. Using Spot for the First Replica Only​

Some teams run 1 on-demand replica + 2 spot replicas, thinking the on-demand one is the "safety net." It isn't — if traffic exceeds what 1 pod can handle and both spots get reclaimed, the on-demand pod falls over. Either run 3 spot replicas with topology spread, or run 2 on-demand + 2 spot as true capacity doubling.

2. Not Diversifying Instance Types​

Running a spot pool with a single instance type (say, m5.xlarge) guarantees that every pod in that pool dies at the same time when AWS reclaims m5.xlarge capacity. Minimum: 5 instance types across 2+ generations. Better: 10+ across m and c families.

3. Long terminationGracePeriodSeconds​

Setting terminationGracePeriodSeconds: 300 on AWS spot is pointless — the node is gone in 120 seconds whether your pod finished or not. Worse, it gives you a false sense of safety. Keep grace periods under 90 seconds for AWS spot, under 25 seconds for GCP/Azure spot.

4. Running Stateful Workloads With emptyDir​

emptyDir volumes live on the node. When the spot node dies, so does the data. If your batch job writes intermediate results to emptyDir, you lose all progress on interruption. Use PVCs (persistent across node loss) or checkpoint to S3/GCS.

5. Ignoring AZ Rebalance Events​

AWS emits a "spot rebalance recommendation" before the hard 2-minute interruption notice — a soft warning that your spot node is likely to be reclaimed soon. Most teams ignore it and wait for the hard notice. Listening for rebalance events lets you drain proactively, before you're under time pressure.

6. Not Setting a Spot Budget​

"We'll use spot everywhere" is not a plan. Define a hard floor for on-demand capacity (system pods, databases, minimum service capacity) and target a spot percentage for the rest. Without a floor, Karpenter will happily schedule your only ingress controller on spot.

7. Forgetting About Cluster Autoscaler Priorities​

If you're on Cluster Autoscaler (not Karpenter), set the --expander=priority flag and assign highest priority to spot node groups. Without it, CA often scales on-demand even when spot is available.

Key Takeaways​

  • Spot is the single biggest cost lever in Kubernetes — 60-90% off compute, realistically 30-50% off the total cluster bill.
  • Classify workloads first. Stateless with 3+ replicas is almost always safe; anything stateful or single-replica is almost never safe.
  • Run a tainted spot pool so workloads must explicitly opt in.
  • Diversify across 10+ instance types and 3+ AZs to avoid correlated evictions.
  • Use topology spread constraints to keep replicas on different nodes.
  • Install a node termination handler (or use Karpenter's built-in) to drain gracefully on the 2-minute warning.
  • Monitor interruption rate — 1-5% is normal, 10%+ means your pool is too narrow.
  • Keep terminationGracePeriodSeconds under the cloud's interruption notice window.

Spot instances are not risky if you treat interruptions as a design constraint instead of a failure mode. The workloads that survive on spot are the same workloads that survive any node failure — which is to say, the ones you should be running anyway.