Cloud & DevOps
Kubernetes Cluster Autoscaling & Spot Instance Fleet Optimization for 60% Cost Reduction
Cloud infrastructure waste routinely accounts for 30–50% of enterprise Kubernetes spend due to overprovisioned node groups and static buffer allocations. Modern FinOps engineering pairs intelligent group-less node autoscaling via Karpenter with diversified Spot instance fleets, unlocking dramatic 60–75% cost reductions without sacrificing workload availability or SLA compliance.
Karpenter Architecture: Right-Sized Just-in-Time Provisioning
Unlike legacy Kubernetes Cluster Autoscaler—which provisions entire homogeneous Auto Scaling Groups (ASGs)—Karpenter directly provisions heterogeneous EC2 instances evaluated against pending Pod compute, memory, and topology spread constraints within sub-minute response times.
# karpenter-node-pool.yaml
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
name: general-compute-spot
spec:
template:
spec:
requirements:
- key: kubernetes.io/arch
operator: In
values: ["amd64", "arm64"] # Leverage Graviton for superior price-performance
- key: karpenter.sh/capacity-type
operator: In
values: ["spot", "on-demand"]
- key: node.kubernetes.io/instance-category
operator: In
values: ["c", "m", "r"]
- key: karpenter.k8s.aws/instance-generation
operator: Gt
values: ["5"]
nodeClassRef:
apiVersion: karpenter.k8s.aws/v1beta1
kind: EC2NodeClass
name: default
disruption:
consolidationPolicy: WhenUnderutilized
expireAfter: 720h # 30 days maximum node age for automated security patching
Handling Spot Termination Notices with AWS Node Termination Handler
AWS provides a 2-minute warning prior to reclaiming Spot capacity. Production clusters must catch Amazon EventBridge termination events to cordoning nodes and gracefully evict state-sensitive workloads before sudden power-off:
# Pod Disruption Budget (PDB) guaranteeing continuous quorum
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: order-service-pdb
namespace: production
spec:
minAvailable: "75%"
selector:
matchLabels:
app: order-service
| Autoscaler Feature | Legacy Cluster Autoscaler | Karpenter (v1beta1+) |
|---|---|---|
| Provisioning Model | Cloud ASG-bound, homogeneous | Group-less, heterogeneous, direct API |
| Scale-Up Latency | 3 to 7 minutes | 45 to 90 seconds |
| Consolidation / Bin-Packing | Rudimentary, prone to fragmentations | Continuous bin-packing & node downgrading |
| Spot Diversification | Manual ASG setup required | Native weighted multi-architecture pooling |
- Diversified Allocation Strategy: Configure
price-capacity-optimizedallocation so AWS automatically provisions instances with the lowest probability of interruption. - Graviton Architecture Adoption: Transitioning container workloads to AWS Graviton (ARM64) yields up to 40% better price-performance over comparable x86 instances.
- Graceful Draining Timeout: Configure
terminationGracePeriodSeconds: 60to allow active HTTP requests to complete cleanly before SIGKILL emission.
