Skip to main content

Command Palette

Search for a command to run...

Prometheus-based Kubernetes Resource Recommendations

Updated
β€’7 min read

Product Name Screen Shot

Kubernetes Resource Recommendations Based on Historical Data

About The Project

Robusta KRR (Kubernetes Resource Recommender) is a CLI tool for optimizing resource allocation in Kubernetes clusters. It gathers pod usage data from Prometheus and recommends requests and limits for CPU and memory. This reduces costs and improves performance.

Data Integrations

Used to send data to KRR

View Instructions for: Prometheus, Thanos, Victoria Metrics, Google Managed Prometheus, Amazon Managed Prometheus, Azure Managed Prometheus, Coralogix,Grafana Cloud and Grafana Mimir

Reporting Integrations

Used to receive information from KRR

View instructions for: Seeing recommendations in a UI, Sending recommendations to Slack, Setting up KRR as a k9s plugin

Features

  • No Agent Required: Run a CLI tool on your local machine for immediate results. (Or run in-cluster for weekly Slack reports.)

  • Prometheus Integration: Get recommendations based on the data you already have

  • Explainability: Understand how recommendations were calculated with explanation graphs

  • Extensible Strategies: Easily create and use your own strategies for calculating resource recommendations.

  • Free SaaS Platform: See why KRR recommends what it does, by using the free Robusta SaaS platform.

  • Future Support: Upcoming versions will support custom resources (e.g. GPUs) and custom metrics.

How Much Can I Expect to Save with KRR?

According to a recent Sysdig study, on average, Kubernetes clusters have:

  • 69% unused CPU

  • 18% unused memory

By right-sizing your containers with KRR, you can save an average of 69% on cloud costs.

Read more about how KRR works

Difference with Kubernetes VPA

Feature πŸ› οΈRobusta KRR πŸš€Kubernetes VPA 🌐
Resource Recommendations πŸ’‘βœ… CPU/Memory requests and limitsβœ… CPU/Memory requests and limits
Installation Location πŸŒβœ… Not required to be installed inside the cluster, can be used on your own device, connected to a cluster❌ Must be installed inside the cluster
Workload Configuration πŸ”§βœ… No need to configure a VPA object for each workload❌ Requires VPA object configuration for each workload
Immediate Results βš‘βœ… Gets results immediately (given Prometheus is running)❌ Requires time to gather data and provide recommendations
Reporting πŸ“Šβœ… Json, CSV, Markdown, Web UI, and more!❌ Not supported
Extensibility πŸ”§βœ… Add your own strategies with few lines of Python⚠️ Limited extensibility
Explainability πŸ“–βœ… See graphs explaining the recommendations❌ Not supported
Custom Metrics πŸ“πŸ”„ Support in future versions❌ Not supported
Custom Resources πŸŽ›οΈπŸ”„ Support in future versions (e.g., GPU)❌ Not supported
Autoscaling πŸ”€πŸ”„ Support in future versionsβœ… Automatic application of recommendations
Default History πŸ•’14 days8 days
Supports HPA πŸ”₯βœ… Enable using --allow-hpa flag❌ Not supported

Installation

Requirements

KRR requires Prometheus 2.26+, kube-state-metrics & cAdvisor.

Which metrics does KRR need?

Installation Methods

Brew (Mac/Linux)
Windows

Airgapped Installation (Offline Environments)

From Source

Additional Options

Environment-Specific Instructions

Setup KRR for...

Trusting custom Certificate Authority (CA) certificate:

If your llm provider url uses a certificate from a custom CA, in order to trust it, base-64 encode the certificate, and store it in an environment variable named CERTIFICATE

Free KRR UI on Robusta SaaS

We highly recommend using the free Robusta SaaS platform. You can:

  • Understand individual app recommendations with app usage history

  • Sort and filter recommendations by namespace, priority, and more

  • Give devs a YAML snippet to fix the problems KRR finds

  • Analyze impact using KRR scan history

Usage

Basic usage
Tweak the recommendation algorithm (strategy)

Giving an Explicit Prometheus URL

Run on specific namespaces

Run on workloads filtered by label

Override the kubectl context

Output formats for reporting (JSON, YAML, CSV, and more)

Centralized Prometheus (multi-cluster)

Prometheus Authentication

Debug mode

How KRR works

Metrics Gathering

Robusta KRR uses the following Prometheus queries to gather usage data:

  • CPU Usage:

      sum(irate(container_cpu_usage_seconds_total{{namespace="{object.namespace}", pod="{pod}", container="{object.container}"}}[{step}]))
    
  • Memory Usage:

      sum(container_memory_working_set_bytes{job="kubelet", metrics_path="/metrics/cadvisor", image!="", namespace="{object.namespace}", pod="{pod}", container="{object.container}"})
    

Need to customize the metrics? Tell us and we'll add support.

Get a free breakdown of KRR recommendations in the Robusta SaaS.

Algorithm

By default, we use a simple strategy to calculate resource recommendations. It is calculated as follows (The exact numbers can be customized in CLI arguments):

  • For CPU, we set a request at the 95th percentile with no limit. Meaning, in 95% of the cases, your CPU request will be sufficient. For the remaining 5%, we set no limit. This means your pod can burst and use any CPU available on the node - e.g. CPU that other pods requested but aren’t using right now.

  • For memory, we take the maximum value over the past week and add a 15% buffer.

Prometheus connection

Find about how KRR tries to find the default Prometheus to connect here.

(back to top)

Data Source Integrations

Prometheus, Victoria Metrics and Thanos auto-discovery

Scanning with a Centralized Prometheus

Azure Managed Prometheus

Google Managed Prometheus (GMP)

Amazon Managed Prometheus

Coralogix Managed Prometheus

Grafana Cloud Managed Prometheus

Grafana Mimir auto-discovery

Integrations

Free UI for KRR recommendations

Slack Notification

Slack Screen Shot

k9s Plugin

Creating a Custom Strategy/Formatter

Look into the examples directory for examples on how to create a custom strategy/formatter.

Testing

We use pytest to run tests.

  1. Install the project manually (see above)

  2. Navigate to the project root directory

  3. Install poetry (https://python-poetry.org/docs/#installing-with-the-official-installer)

  4. Install dev dependencies:

poetry install --group dev
  1. Install robusta_krr as editable dependency:
pip install -e .
  1. Run the tests:
poetry run pytest

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project

  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)

  3. Commit your Changes (git commit -m 'Add some AmazingFeature')

  4. Push to the Branch (git push origin feature/AmazingFeature)

  5. Open a Pull Request

More from this blog

SRE Tribe

413 posts