Skip to main content

Predictive Resource Optimizer for Kubernetes — identifies over-provisioned deployments and generates right-sizing patches

Project description

kube-foresight

Right-size your Kubernetes deployments, forecast resource trends, and estimate the multi-cloud cost impact — in one tool, with kubectl-ready patches.

CI License Python PyPI Status

Dashboard overview

What it does

Most teams over-provision Kubernetes by 40–70% out of fear of outages — and fixing it usually means stitching several tools together: one to recommend new resources, another to apply them, another to watch for future breaches, another to price the change.

kube-foresight runs that whole loop in a single CLI and dashboard:

recommendation → kubectl-ready patch → breach forecast → multi-cloud cost

It reads live usage from your Metrics API or Prometheus, recommends right-sized requests and limits, emits a patch you review and kubectl apply, predicts when usage will breach current limits, and prices the reclaimed capacity across AWS / GCP / Azure.

Status: Alpha — under active development. Analysis is read-only (the CLI never changes your cluster), so it's safe to evaluate against real workloads; validate recommendations before applying them at scale. Production deployment reports, issues, and PRs especially welcome.

Install

pip install "kube-foresight[dashboard]"   # Python 3.10+

Prefer a container? See Deployment.

Use it on your cluster

kube-foresight reads usage from the Kubernetes Metrics API (via metrics-server) or Prometheus. It never edits workloads itself — it writes patch files you apply on your own terms.

# 1. Find over-provisioned deployments
kube-foresight analyze   -n production --mode k8s
kube-foresight recommend -n production --mode prometheus -p http://prometheus:9090

# 2. Generate kubectl-ready patches — review, then apply
kube-foresight patch -n production --mode k8s -o ./patches
kubectl apply -f ./patches/api-gateway-patch.yaml

# 3. Forecast when usage will breach current limits
kube-foresight forecast -n production --mode k8s

Preview without a cluster

See the full pipeline and dashboard against representative sample workloads — no cluster, RBAC, or metrics-server required:

kube-foresight demo                 # full pipeline, sample data
kube-foresight dashboard --demo     # web UI at http://localhost:8080

Recommendations view

Why trust the recommendations

Right-sizing is only useful if it doesn't cause the outages teams over-provision to avoid. kube-foresight is built defensively:

  • It never auto-applies. It recommends and generates patches; every change to your cluster is one you trigger (kubectl apply, or the dashboard's apply action).
  • Sizes on real demand. Recommendations use p95 / p99 of observed usage with configurable headroom, computed on raw data so demand spikes aren't discarded — under-provisioning is the dangerous error, so it errs toward the tail.
  • Per-resource. CPU and memory are sized independently; a CPU-wasteful workload pinned at its memory limit gets its CPU cut without touching memory.
  • HPA-aware. It refuses to recommend changes that would fight a HorizontalPodAutoscaler.
  • Backtested. Recommendations are validated against a public production trace (Alibaba 2018) with a held-out train/test split. The methodology and results are in benchmarks/.

What's in the box

  • Three collectors — Kubernetes Metrics API, Prometheus, or mock (demo / CI)
  • Statistical right-sizing — p95 / p99 / max strategies (p99 default), CPU and memory sized independently with configurable headroom
  • Forecasting — linear-regression breach-time prediction with risk classification
  • Multi-cloud cost estimation — prices reclaimable CPU/memory at approximate on-demand rates for AWS / GCP / Azure
  • Patch generator — strategic-merge YAML you can kubectl apply
  • Web dashboard — FastAPI + HTMX + Chart.js (overview, recommendations, cost comparison)
  • Production plumbing — Dockerfile, Helm chart, health probes, structured JSON logs, optional Slack alerts

How costs are calculated: figures reflect reclaimable capacity — the difference between current and recommended requests, priced at approximate blended on-demand rates for the selected provider. Translating reclaimed capacity into billing changes depends on node consolidation by the cluster autoscaler; pair with Kubecost/OpenCost for allocation-accurate spend.

Where it fits

Several tools cover individual pieces of this well:

  • KRR — Prometheus-based right-sizing recommendations.
  • Goldilocks — surfaces VPA recommendations across a cluster.
  • VPA — in-cluster vertical autoscaling that can apply changes automatically.
  • Kubecost / OpenCost — allocation-accurate cost monitoring and spend reporting.

kube-foresight's niche is bringing right-sizing, breach forecasting, kubectl patch output, and side-by-side multi-cloud pricing into one workflow. If KRR already covers your recommendations and Kubecost your spend, you may not need it — it's for teams who'd rather run one loop than wire several tools together.

CLI reference

Command Purpose
demo Full pipeline with sample data — no cluster required
analyze Identify over-provisioned deployments
collect Snapshot metrics into SQLite for trend analysis
recommend Right-sizing recommendations + cost estimates
patch Generate kubectl-applyable YAML patches
forecast Predict resource trends and breach timelines
dashboard Launch the web UI

Common flags: --namespace/-n, --mode/-m {mock,k8s,prometheus}, --prometheus-url/-p, --strategy/-s {p95,p99,max}, --headroom 0.20, --top 10, --lookback 168.

Deployment

Docker

# Pull the published image (GitHub Container Registry)
docker run -p 8080:8080 ghcr.io/pallaprolus/kube-foresight:latest \
  dashboard --host 0.0.0.0 --port 8080 --demo

# …or build from source
docker build -t kube-foresight .
docker run -p 8080:8080 kube-foresight dashboard --host 0.0.0.0 --port 8080 --demo

Helm

helm install kube-foresight charts/kube-foresight \
  --set collector.mode=k8s \
  --set collector.namespaces=production \
  --set scheduler.enabled=true

See charts/kube-foresight/values.yaml for persistence, ingress, alerting, and authentication options.

Configuration

All settings are environment variables prefixed KF_:

Variable Purpose Default
KF_MODE Collector mode (mock, k8s, prometheus) k8s
KF_NAMESPACES Comma-separated namespaces default
KF_CLOUD_PROVIDER Pricing source: aws, gcp, azure aws
KF_SCHEDULER_ENABLED Background collect/analyze loop false
KF_COLLECT_INTERVAL Collection interval (seconds) 300
KF_ANALYSIS_INTERVAL Analysis interval (seconds) 900
KF_SLACK_WEBHOOK_URL Slack alerts for at-risk deployments
KF_LOG_FORMAT text or json text

Development

git clone https://github.com/pallaprolus/kube-foresight && cd kube-foresight
pip install -e ".[k8s,dashboard,dev]"
pytest tests/ -v --tb=short        # 251 tests
ruff check .
helm lint charts/kube-foresight

For codebase layout, conventions, and the data-flow diagram, see docs/architecture.md.

Contributing

Issues and PRs are very welcome — particularly: real-world deployment reports, additional pricing providers, and validation of forecast accuracy on production traces. See CONTRIBUTING.md once filed.

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kube_foresight-0.3.1.tar.gz (76.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kube_foresight-0.3.1-py3-none-any.whl (94.5 kB view details)

Uploaded Python 3

File details

Details for the file kube_foresight-0.3.1.tar.gz.

File metadata

  • Download URL: kube_foresight-0.3.1.tar.gz
  • Upload date:
  • Size: 76.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kube_foresight-0.3.1.tar.gz
Algorithm Hash digest
SHA256 93a4643d6629946408877ebcb8d6287f54f22db49f8f8ee78c058eab4756983c
MD5 d52b19ffbcf658cbb53d561cc998b06a
BLAKE2b-256 f48b2eb0bbd17192bf1e38ffb46ebccd69b459702c8f85ff87ae95e5229d1824

See more details on using hashes here.

Provenance

The following attestation bundles were made for kube_foresight-0.3.1.tar.gz:

Publisher: publish.yml on pallaprolus/kube-foresight

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kube_foresight-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: kube_foresight-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 94.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kube_foresight-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d226c7a17355b5993396f5cd403d6db4f34104d6dfc55d70f0750682399e325e
MD5 e84a7b31c744f4dae8461c6614a019b0
BLAKE2b-256 942f5b5d18b412065f2b8689dca2e06728f5ec4ae9fc7fe7c6799dd6805cfb6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kube_foresight-0.3.1-py3-none-any.whl:

Publisher: publish.yml on pallaprolus/kube-foresight

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page