Building a Cost-Aware Kubernetes Autoscaler with Karpenter

Written by

in

Default Kubernetes cluster autoscaler treats all nodes equally, which leads to surprisingly expensive infrastructure bills when your workloads have mixed resource profiles. We built a custom Karpenter provisioner configuration that reduced our AWS compute costs by 34% without affecting application performance.

The key insight was separating workloads into three tiers based on their interruption tolerance. Batch jobs and dev environments run on spot instances with Karpenter consolidation enabled. Stateless API servers use a mix of on-demand and spot with automatic failover. Stateful services like databases and message queues stay on dedicated on-demand instances with local NVMe storage.

We also implemented a custom webhook that injects resource requests based on historical usage data from our Prometheus metrics, solving the chronic under-requesting problem that plagues most Kubernetes deployments.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *