DevOps Peach

FinOps Foundations · Optimize Usage and Cost · Lesson 4 of 4

Kubernetes Cost Allocation and Optimization

Kubernetes hides cost behind shared nodes; OpenCost and similar tools allocate node cost to namespaces and workloads by requests and usage, and savings come from right-sizing requests, bin packing, autoscaling and spot node pools.

Practice interactively →

The cloud bill shows nodes, not teams. A cluster with 20 namespaces is one big shared cost until you allocate it.

flowchart LR
  NODES["Node cost from the bill"] --> OC["OpenCost / Kubecost"]
  REQ["Pod requests and usage"] --> OC
  OC --> NS["Cost per namespace, label, workload"]
  OC --> IDLE["Idle: capacity nobody requested"]
  NS --> RS["Right-size requests"]
  IDLE --> BP["Bin packing and autoscaling"]
  %% step NODES: Providers bill VMs, disks and load balancers; the cluster itself is opaque.
  %% step REQ: Pod CPU and memory requests reserve capacity whether they are used or not.
  %% step OC: OpenCost (a CNCF project) combines prices with requests and usage to allocate cost.
  %% step NS: Cost per namespace or label maps to teams, just like tags elsewhere.
  %% step IDLE: Capacity no pod requested is idle cost — usually shared out or shown separately.
  %% step RS: Lowering inflated requests is the biggest lever; then nodes can shrink.

How allocation works

Each pod is charged for max(request, usage) of CPU and memory, multiplied by the node's price per CPU-hour and GB-hour. Persistent volumes and load balancers are added directly. Unrequested capacity is idle cost.

Optimisation levers

Lever What it does
Right-size requests Requests close to real usage (e.g. Vertical Pod Autoscaler recommendations)
Horizontal Pod Autoscaler Scale replicas with load instead of sizing for peak
Cluster autoscaler / Karpenter Add and remove nodes, consolidate pods onto fewer nodes
Spot node pools Run stateless and batch workloads on spot capacity
Namespace quotas and LimitRanges Stop unbounded requests; give defaults
Schedule dev clusters Scale node pools to zero after hours

Typical numbers to watch

Traps: allocating by usage only (teams that over-request look cheap while blocking capacity); setting requests lower than real needs, which causes throttling and evictions; and putting stateful workloads on spot nodes without disruption handling.

Practice interactively →