Skip to content

Commit

Permalink
Merge branch 'main' into document-openshift-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi-Robusta committed May 22, 2024
2 parents 11ba7a1 + a36063c commit 2767abe
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 55 deletions.
77 changes: 51 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
<br />
<a href="#installation"><strong>Installation</strong></a>
.
<a href="#usage"><strong>Usage</strong></a>
·
<a href="#how-krr-works"><strong>How KRR works</strong></a>
.
<a href="#slack-integration"><strong>Slack Integration</strong></a>
.
<a href="#free-krr-ui-on-robusta-saas"><strong>KRR UI on Robusta Cloud</strong></a>
<br />
<a href="#usage">Usage</a>
·
<a href="https://github.com/robusta-dev/krr/issues">Report Bug</a>
·
<a href="https://github.com/robusta-dev/krr/issues">Request Feature</a>
·
<a href="#support">Support</a>
<br /> Like KRR? Please ⭐ this repository to show your support!
</p>
</div>
<!-- TABLE OF CONTENTS -->
Expand Down Expand Up @@ -60,7 +63,7 @@

## 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.
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

Expand All @@ -83,7 +86,7 @@ _View instructions for: [Seeing recommendations in a UI](#free-ui-for-krr-recomm
- **Prometheus Integration**: Get recommendations based on the data you already have
- **Explainability**: Understand how recommendations were calculated
- **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](https://home.robusta.dev/).
- **Free SaaS Platform**: See why KRR recommends what it does, by using the [free Robusta SaaS platform](https://platform.robusta.dev/signup/?utm_source=github&utm_medium=krr-readme).
- **Future Support**: Upcoming versions will support custom resources (e.g. GPUs) and custom metrics.

### Why Use KRR?
Expand All @@ -95,11 +98,29 @@ According to a recent [Sysdig study](https://sysdig.com/blog/millions-wasted-kub

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

Read more about [how KRR works](#how-krr-works) and [KRR vs Kubernetes VPA](#difference-with-kubernetes-vpa)
Read more about [how KRR works](#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 📊 | ✅ Detailed CLI Report, web UI in [Robusta.dev](https://home.robusta.dev/) | ❌ Not supported |
| Extensibility 🔧 | ✅ Add your own strategies with few lines of Python | :warning: 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 days | 8 days |
| Supports HPA 🔥 | ✅ Enable using `--allow-hpa` flag | ❌ Not supported |


<!-- GETTING STARTED -->

## Installation
## Installation

### Requirements

Expand All @@ -120,6 +141,7 @@ If you have a different setup, make sure the following metrics exist:
_Note: If one of last three metrics is absent KRR will still work, but it will only consider currently-running pods when calculating recommendations. Historic pods that no longer exist in the cluster will not be taken into consideration._
</details>


### Installation Methods

<details>
Expand Down Expand Up @@ -212,8 +234,23 @@ Setup KRR for...

<p align="right">(<a href="#readme-top">back to top</a>)</p>


## Free KRR UI on Robusta SaaS

We highly recommend using the [free Robusta SaaS platform](https://platform.robusta.dev/signup/?utm_source=github&utm_medium=krr-readme). 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

<a href="https://www.loom.com/share/49ea188f67c545f0ae98508b448d1a8b">
<img src="https://cdn.loom.com/sessions/thumbnails/49ea188f67c545f0ae98508b448d1a8b-with-play.gif">
</a>

<!-- USAGE EXAMPLES -->


## Usage

<details>
Expand Down Expand Up @@ -369,7 +406,7 @@ Robusta KRR uses the following Prometheus queries to gather usage data:

[_Need to customize the metrics? Tell us and we'll add support._](https://github.com/robusta-dev/krr/issues/new)

Get a free breakdown of KRR recommendations in the [Robusta SaaS](#optional-free-saas-platform).
Get a free breakdown of KRR recommendations in the [Robusta SaaS](#free-krr-ui-on-robusta-saas).

### Algorithm

Expand All @@ -385,21 +422,6 @@ Find about how KRR tries to find the default Prometheus to connect <a href="#pro

<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 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 📊 | ✅ Detailed CLI Report, web UI in [Robusta.dev](https://home.robusta.dev/) | ❌ Not supported |
| Extensibility 🔧 | ✅ Add your own strategies with few lines of Python | :warning: 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 days | 8 days |

<!-- ADVANCED USAGE EXAMPLES -->

Expand Down Expand Up @@ -567,13 +589,16 @@ For discovering Prometheus it scans services for those labels:
<details id="free-ui-for-krr-recommendations">
<summary>Free UI for KRR recommendations</summary>

With the [free Robusta SaaS platform](https://home.robusta.dev/) you can:
We highly recommend using the [free Robusta SaaS platform](https://platform.robusta.dev/signup/?utm_source=github&utm_medium=krr-readme). You can:

- See why KRR recommends what it does
- Understand individual app recommendations with app usage history
- Sort and filter recommendations by namespace, priority, and more
- Copy a YAML snippet to fix the problems KRR finds
- Give dev's a YAML snippet to fix the problems KRR finds
- Analyze impact using KRR scan history

![Robusta UI Screen Shot][ui-screenshot]
<a href="https://www.loom.com/share/49ea188f67c545f0ae98508b448d1a8b">
<img src="https://cdn.loom.com/sessions/thumbnails/49ea188f67c545f0ae98508b448d1a8b-with-play.gif">
</a>

</details>

Expand Down
15 changes: 3 additions & 12 deletions robusta_krr/core/abstract/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,15 @@ def __init__(self, settings: _StrategySettings):
self.settings = settings

def __str__(self) -> str:
return self._display_name.title()

@property
def _display_name(self) -> str:
return getattr(self, "display_name", self.__class__.__name__.lower().removeprefix("strategy"))
return self.display_name.title()

@property
def description(self) -> Optional[str]:
"""
Generate a description for the strategy.
You can use the settings in the description by using the format syntax.
Also you can use Rich's markdown syntax to format the description.
You can use Rich's markdown syntax to format the description.
"""

if self.__doc__ is None:
return None

return f"[b]{self} Strategy[/b]\n\n" + dedent(self.__doc__.format_map(self.settings.dict())).strip()
raise NotImplementedError()

# Abstract method that needs to be implemented by subclass.
# This method is intended to calculate resource recommendation based on history data and kubernetes object data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def find_metrics_url(self, *, api_client: Optional[ApiClient] = None) -> Optiona
"app=rancher-monitoring-prometheus",
"app=prometheus-prometheus",
"app.kubernetes.io/name=prometheus,app.kubernetes.io/component=server",
"app=stack-prometheus",
]
)

Expand Down
2 changes: 1 addition & 1 deletion robusta_krr/core/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async def _collect_result(self) -> Result:

return Result(
scans=scans,
description=self._strategy.description,
description=f"[b]{self._strategy.display_name.title()} Strategy[/b]\n\n{self._strategy.description}",
strategy=StrategyData(
name=str(self._strategy).lower(),
settings=self._strategy.settings.dict(),
Expand Down
40 changes: 24 additions & 16 deletions robusta_krr/strategies/simple.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
from datetime import timedelta

import numpy as np
Expand All @@ -24,7 +25,7 @@


class SimpleStrategySettings(StrategySettings):
cpu_percentile: float = pd.Field(99, gt=0, le=100, description="The percentile to use for the CPU recommendation.")
cpu_percentile: float = pd.Field(95, gt=0, le=100, description="The percentile to use for the CPU recommendation.")
memory_buffer_percentage: float = pd.Field(
15, gt=0, description="The percentage of added buffer to the peak memory usage for memory recommendation."
)
Expand Down Expand Up @@ -70,21 +71,7 @@ def history_range_enough(self, history_range: tuple[timedelta, timedelta]) -> bo


class SimpleStrategy(BaseStrategy[SimpleStrategySettings]):
"""
CPU request: {cpu_percentile}% percentile, limit: unset
Memory request: max + {memory_buffer_percentage}%, limit: max + {memory_buffer_percentage}%
History: {history_duration} hours
Step: {timeframe_duration} minutes
All parameters can be customized. For example: `krr simple --cpu_percentile=90 --memory_buffer_percentage=15 --history_duration=24 --timeframe_duration=0.5`
This strategy does not work with objects with HPA defined (Horizontal Pod Autoscaler).
If HPA is defined for CPU or Memory, the strategy will return "?" for that resource.
You can override this behaviour by passing the --allow-hpa flag
Learn more: [underline]https://github.com/robusta-dev/krr#algorithm[/underline]
"""


display_name = "simple"
rich_console = True

Expand All @@ -102,6 +89,27 @@ def metrics(self) -> list[type[PrometheusMetric]]:

return metrics

@property
def description(self):
s = textwrap.dedent(f"""\
CPU request: {self.settings.cpu_percentile}% percentile, limit: unset
Memory request: max + {self.settings.memory_buffer_percentage}%, limit: max + {self.settings.memory_buffer_percentage}%
History: {self.settings.history_duration} hours
Step: {self.settings.timeframe_duration} minutes
All parameters can be customized. For example: `krr simple --cpu_percentile=90 --memory_buffer_percentage=15 --history_duration=24 --timeframe_duration=0.5`
""")

if not self.settings.allow_hpa:
s += "\n" + textwrap.dedent(f"""\
This strategy does not work with objects with HPA defined (Horizontal Pod Autoscaler).
If HPA is defined for CPU or Memory, the strategy will return "?" for that resource.
You can override this behaviour by passing the --allow-hpa flag
""")

s += "\nLearn more: [underline]https://github.com/robusta-dev/krr#algorithm[/underline]"
return s

def __calculate_cpu_proposal(
self, history_data: MetricsPodData, object_data: K8sObjectData
) -> ResourceRecommendation:
Expand Down

0 comments on commit 2767abe

Please sign in to comment.