Loading_
Loading_
Reads 14 days of Prometheus history and emits per-workload requests and limits at the percentiles you choose, as a patch file you can review before applying.
"""Rightsize Kubernetes requests and limits from Prometheus history. pip install requests pyyaml python k8s_rightsize.py --prometheus http://prom:9090 --namespace prod \ --days 14 --out patches.yaml Emits a patch file. Applies nothing.""" from __future__ import annotations import argparseimport mathimport sysfrom dataclasses import dataclass import requestsimport yaml # Headroom multipliers. Requests sit above typical usage so the scheduler# packs honestly; limits sit above the worst observed spike so a burst is# absorbed rather than throttled.REQUEST_HEADROOM = 1.15LIMIT_HEADROOM = 1.30MIN_CPU_MILLICORES = 10MIN_MEMORY_MI = 32 136 more lines behind the library licence
k8s_rightsize.py · 5.6 KB · 3 dependencies documented
This one is behind the licence because it is the kind of script that does real damage when it is wrong — and the version above has already been broken and fixed by two engineers in a live estate.
Requests set from a guess are the single largest source of cloud waste in a Kubernetes estate, and limits set from the same guess are the largest source of inexplicable throttling.
This queries Prometheus for CPU and memory over a rolling window, computes p50/p95/p99 per container, and proposes requests at p50 with headroom and limits at p99 with a ceiling — the shape that keeps the scheduler honest without OOM-killing a workload during a spike.
Output is a kubectl patch file plus a summary of what changes. It never applies anything: rightsizing is a change that needs a human to look at the diff, because the model cannot know which workloads are latency-critical.
| Name | Type | Required | Description |
|---|---|---|---|
--prometheus | url | Required | Prometheus base URL. |
--namespace | string | Required | Namespace to analyse. |
--days | int | Optional | History window, default 14. |
The platform turns any script into a governed automation — versioned, gated, audited and reversible.