From e032745f670f1923722571f1be041de7e8b63e5e Mon Sep 17 00:00:00 2001
From: Natan Yellin
@@ -62,17 +62,18 @@
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.
-_Supports: [Prometheus](#prometheus-victoria-metrics-and-thanos-auto-discovery), [Thanos](#prometheus-victoria-metrics-and-thanos-auto-discovery), [Victoria Metrics](#prometheus-victoria-metrics-and-thanos-auto-discovery), [Amazon Managed Prometheus](#amazon-managed-prometheus), [Azure](#azure-managed-prometheus), [Coralogix](#coralogix-managed-prometheus) and [Grafana Cloud](#grafana-cloud-managed-prometheus)_
+_Supports: [Prometheus](#prometheus-victoria-metrics-and-thanos-auto-discovery), [Thanos](#prometheus-victoria-metrics-and-thanos-auto-discovery), [Victoria Metrics](#prometheus-victoria-metrics-and-thanos-auto-discovery), [Google Managed Prometheus](./docs/google-cloud-managed-service-for-prometheus.md), [Amazon Managed Prometheus](#amazon-managed-prometheus), [Azure Managed Prometheus](#azure-managed-prometheus), [Coralogix](#coralogix-managed-prometheus) and [Grafana Cloud](#grafana-cloud-managed-prometheus)_
### Features
- **No Agent Required**: Run a CLI tool on your local machine for immediate results. (Or run in-cluster for weekly [Slack reports](#slack-integration).)
- **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/).
- **Future Support**: Upcoming versions will support custom resources (e.g. GPUs) and custom metrics.
-### Resource Allocation Statistics
+### Why Use KRR?
According to a recent [Sysdig study](https://sysdig.com/blog/millions-wasted-kubernetes/), on average, Kubernetes clusters have:
@@ -101,7 +102,10 @@ Additionally to that, [kube-state-metrics](https://github.com/kubernetes/kube-st
_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._
-### With brew (MacOS/Linux):
+### Installation Methods
+
+Brew (Mac/Linux)
1. Add our tap:
@@ -120,12 +124,16 @@ brew install krr
```sh
krr --help
```
+Windows
-You can install using brew (see above) on [WSL2](https://docs.brew.sh/Homebrew-on-Linux), or install manually.
+You can install using brew (see above) on [WSL2](https://docs.brew.sh/Homebrew-on-Linux), or install from source (see below).
+From Source
1. Make sure you have [Python 3.9](https://www.python.org/downloads/) (or greater) installed
2. Clone the repo:
@@ -150,37 +158,73 @@ python krr.py --help
Notice that using source code requires you to run as a python script, when installing with brew allows to run `krr`.
All above examples show running command as `krr ...`, replace it with `python krr.py ...` if you are using a manual installation.
-
+Basic usage
+
```sh
krr simple
```
+Tweak the recommendation algorithm
+
+Most helpful flags:
-If you want only specific namespaces (default and ingress-nginx):
+- `--cpu-min` Sets the minimum recommended cpu value in millicores
+- `--mem-min` Sets the minimum recommended memory value in MB
+- `--history_duration` The duration of the prometheus history data to use (in hours)
+
+More specific information on Strategy Settings can be found using
+
+```sh
+krr simple --help
+```
+Run on specific namespaces
+
+List as many namespaces as you want with `-n` (in this case, `default` and `ingress-nginx`)
```sh
krr simple -n default -n ingress-nginx
```
+Run on workloads filtered by label
+
+Use a label selector
```sh
python krr.py simple --selector 'app.kubernetes.io/instance in (robusta, ingress-nginx)'
```
+Override the kubectl context
By default krr will run in the current context. If you want to run it in a different context:
@@ -188,36 +232,80 @@ By default krr will run in the current context. If you want to run it in a diffe
krr simple -c my-cluster-1 -c my-cluster-2
```
-If you want to get the output in JSON format (--logtostderr is required so no logs go to the result file):
+Customize output (JSON, YAML, and more
+
+Currently KRR ships with a few formatters to represent the scan data:
+
+- `table` - a pretty CLI table used by default, powered by [Rich](https://github.com/Textualize/rich) library
+- `json`
+- `yaml`
+- `pprint` - data representation from python's pprint library
+
+To run a strategy with a selected formatter, add a `-f` flag:
+
+```sh
+krr simple -f json
+```
+
+For JSON output, add --logtostderr so no logs go to the result file:
```sh
krr simple --logtostderr -f json > result.json
```
-If you want to get the output in YAML format:
+For YAML output, do the same:
```sh
krr simple --logtostderr -f yaml > result.yaml
```
+Centralized Prometheus (multi-cluster)
+
+If your Prometheus monitors multiple clusters we require the label you defined for your cluster in Prometheus.
+
+For example, if your cluster has the Prometheus label `cluster: "my-cluster-name"`, then run this command:
```sh
-krr simple -v
+krr.py simple --prometheus-label cluster -l my-cluster-name
```
-Other helpful flags:
+You may also need the `-p` flag to explicitly give Prometheus' URL.
-- `--cpu-min` Sets the minimum recommended cpu value in millicores
-- `--mem-min` Sets the minimum recommended memory value in MB
-- `--history_duration` The duration of the prometheus history data to use (in hours)
-More specific information on Strategy Settings can be found using
+Giving an Explicit Prometheus URL
+
+If your prometheus is not auto-connecting, you can use `kubectl port-forward` for manually forwarding Prometheus.
+
+For example, if you have a Prometheus Pod called `kube-prometheus-st-prometheus-0`, then run this command to port-forward it:
```sh
-krr simple --help
+kubectl port-forward pod/kube-prometheus-st-prometheus-0 9090
+```
+
+Then, open another terminal and run krr in it, giving an explicit prometheus url:
+
+```sh
+krr simple -p http://127.0.0.1:9090
+```
+Debug mode
+If you want to see additional debug logs:
+
+```sh
+krr simple -v
```
+