From bb1f3dd01d1486ebe0f80e586f0c0cda6f644da2 Mon Sep 17 00:00:00 2001 From: Robusta Runner Date: Fri, 10 May 2024 00:14:40 +0300 Subject: [PATCH 01/10] Don't show HPA warning if user chooses to run w/ HPA --- robusta_krr/core/abstract/strategies.py | 15 ++-------- robusta_krr/core/runner.py | 2 +- robusta_krr/strategies/simple.py | 38 +++++++++++++++---------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/robusta_krr/core/abstract/strategies.py b/robusta_krr/core/abstract/strategies.py index 0005a227..b63b2cc7 100644 --- a/robusta_krr/core/abstract/strategies.py +++ b/robusta_krr/core/abstract/strategies.py @@ -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. diff --git a/robusta_krr/core/runner.py b/robusta_krr/core/runner.py index 8e08521c..7ae4a40d 100644 --- a/robusta_krr/core/runner.py +++ b/robusta_krr/core/runner.py @@ -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(), diff --git a/robusta_krr/strategies/simple.py b/robusta_krr/strategies/simple.py index 3cecd18e..3a781f4e 100644 --- a/robusta_krr/strategies/simple.py +++ b/robusta_krr/strategies/simple.py @@ -1,3 +1,4 @@ +import textwrap from datetime import timedelta import numpy as np @@ -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 @@ -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: From 0bc47368c546fd0d546a831467bc964c89fd5a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Gon=C3=A7alves?= <30077840+joaopedrocg27@users.noreply.github.com> Date: Mon, 13 May 2024 10:05:29 +0100 Subject: [PATCH 02/10] fix(discovery): Added selector for prometheus-stack --- .../prometheus/metrics_service/prometheus_metrics_service.py | 1 + 1 file changed, 1 insertion(+) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 8331249f..97dcd185 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -35,6 +35,7 @@ def find_metrics_url(self, *, api_client: Optional[ApiClient] = None) -> Optiona return super().find_url( selectors=[ "app=kube-prometheus-stack-prometheus", + "app=stack-prometheus", "app=prometheus,component=server", "app=prometheus-server", "app=prometheus-operator-prometheus", From 8de631b6e4a36c64319a24d798713641d78bbb1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Gon=C3=A7alves?= <30077840+joaopedrocg27@users.noreply.github.com> Date: Tue, 14 May 2024 08:56:06 +0100 Subject: [PATCH 03/10] Update prometheus_metrics_service.py --- .../prometheus/metrics_service/prometheus_metrics_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py index 97dcd185..90efdc16 100644 --- a/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py +++ b/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py @@ -35,13 +35,13 @@ def find_metrics_url(self, *, api_client: Optional[ApiClient] = None) -> Optiona return super().find_url( selectors=[ "app=kube-prometheus-stack-prometheus", - "app=stack-prometheus", "app=prometheus,component=server", "app=prometheus-server", "app=prometheus-operator-prometheus", "app=rancher-monitoring-prometheus", "app=prometheus-prometheus", "app.kubernetes.io/name=prometheus,app.kubernetes.io/component=server", + "app=stack-prometheus", ] ) From 00c738d65d1a1684755a13a3f5a13b4a86c67a34 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Mon, 20 May 2024 16:14:56 +0530 Subject: [PATCH 04/10] Updated KRR readme --- README.md | 58 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 33650c3c..6ab7d671 100644 --- a/README.md +++ b/README.md @@ -18,17 +18,20 @@
Installation . - Usage - · How KRR works . Slack Integration + . + KRR UI on Robusta Cloud
+ Usage + · Report Bug · Request Feature · Support +
Like KRR? Please ⭐ this repository to show your support!

@@ -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 @@ -97,6 +100,23 @@ By right-sizing your containers with KRR, you can save an average of 69% on clou Read more about [how KRR works](#how-krr-works) and [KRR vs Kubernetes VPA](#difference-with-kubernetes-vpa) +## 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 | + + ## Installation @@ -120,6 +140,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._ + ### Installation Methods
@@ -212,8 +233,15 @@ Setup KRR for...

(back to top)

+ + +## Free KRR UI on Robusta SaaS + +
+ + ## Usage
@@ -385,21 +413,6 @@ Find about how KRR tries to find the default Prometheus to connect (back to top)

-## 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 | @@ -567,13 +580,14 @@ For discovering Prometheus it scans services for those labels:
Free UI for KRR recommendations -With the [free Robusta SaaS platform](https://home.robusta.dev/) you can: +With 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] +
From d4ed7ce52cea124669cfed340321a521ce40a828 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Mon, 20 May 2024 16:28:37 +0530 Subject: [PATCH 05/10] Updated video links --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 6ab7d671..f558b7dd 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,15 @@ Setup KRR for...
+ + + + + + + + + ## Usage
From d8c3d26b0774c781498c27cdc19e20b183b42d5f Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Mon, 20 May 2024 16:36:26 +0530 Subject: [PATCH 06/10] Updated broken links --- README.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f558b7dd..9faf6e5a 100644 --- a/README.md +++ b/README.md @@ -86,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? @@ -234,22 +234,21 @@ Setup KRR for...

(back to top)

- - - ## 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 dev's a YAML snippet to fix the problems KRR finds +- Analyze impact using KRR scan history - + + + ## Usage @@ -406,7 +405,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 @@ -596,7 +595,9 @@ With the [free Robusta SaaS platform](https://platform.robusta.dev/signup/?utm_s - Give dev's a YAML snippet to fix the problems KRR finds - Analyze impact using KRR scan history -
+ + +
From 88b25afac06becc7f5b2135b688adf3b4ec6d327 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Mon, 20 May 2024 16:50:31 +0530 Subject: [PATCH 07/10] Fixed inconsistency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9faf6e5a..c668638f 100644 --- a/README.md +++ b/README.md @@ -588,7 +588,7 @@ For discovering Prometheus it scans services for those labels:
Free UI for KRR recommendations -With the [free Robusta SaaS platform](https://platform.robusta.dev/signup/?utm_source=github&utm_medium=krr-readme) 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: - Understand individual app recommendations with app usage history - Sort and filter recommendations by namespace, priority, and more From 4f4196392168b2813394dbbc9de29950b8b4b167 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Mon, 20 May 2024 17:01:03 +0530 Subject: [PATCH 08/10] Added HPA suport details --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c668638f..db26bf2a 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ 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 @@ -115,11 +115,12 @@ Read more about [how KRR works](#how-krr-works) and [KRR vs Kubernetes VPA](#dif | 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 | -## Installation +## Installation ### Requirements From c24f4754aefda2b86778c838b8834ef6dacfe763 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Mon, 20 May 2024 20:27:05 +0530 Subject: [PATCH 09/10] Fixed minor update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db26bf2a..012b19bf 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ We highly recommend using the [free Robusta SaaS platform](https://platform.robu - Understand individual app recommendations with app usage history - Sort and filter recommendations by namespace, priority, and more -- Give dev's a YAML snippet to fix the problems KRR finds +- Give devs a YAML snippet to fix the problems KRR finds - Analyze impact using KRR scan history From a36063c0cb04c4a6e7c58ebc3cd646305b53a020 Mon Sep 17 00:00:00 2001 From: Avi-Robusta <97387909+Avi-Robusta@users.noreply.github.com> Date: Wed, 22 May 2024 11:25:27 +0300 Subject: [PATCH 10/10] reducing cpu precentile for better rec (#282) --- robusta_krr/strategies/simple.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robusta_krr/strategies/simple.py b/robusta_krr/strategies/simple.py index 3a781f4e..c56e6ecb 100644 --- a/robusta_krr/strategies/simple.py +++ b/robusta_krr/strategies/simple.py @@ -25,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." )