国产在线视频精品视频,国产亚洲精品久久久久久青梅 ,国产麻豆精品一区,国产真实乱对白精彩久久,国产精品视频一区二区三区四

加載中...
您的位置:首頁 >焦點 > 正文

Robusta KRR – 一個優(yōu)化 Kubernetes 的資源分配工具_(dá)全球時訊

2023-05-31 19:36:19 來源:清一色財經(jīng)

如果你使用 Robusta SaaS,從 v0.10.15 開始回集成 KRR,你可以查看所有建議(也包括以前的建議),按集群、命名空間或名稱過濾和排序它們。

Robusta KRR(Kubernetes Resource Recommender)是一個用于優(yōu)化 Kubernetes 集群中資源分配的命令行工具,它從 Prometheus 收集 pod 使用數(shù)據(jù),并建議 CPU 和內(nèi)存的 requests 和 limits 值,這可以大大降低成本并提高性能。


(資料圖片)

特征

無需代理:Robusta KRR 是一個在本地機(jī)器上運行的 CLI 工具,它不需要在你的集群中運行 Pods。Prometheus 集成:使用內(nèi)置的 Prometheus 查詢收集資源使用數(shù)據(jù),自定義查詢支持也即將推出??蓴U(kuò)展策略:輕松創(chuàng)建和使用你自己的策略來計算資源推薦。未來支持:即將推出的版本將支持自定義資源(例如 GPU)和自定義指標(biāo)。

根據(jù) Sysdig 最近的一項研究(https://sysdig.com/blog/millions-wasted-kubernetes/),平均而言,Kubernetes 集群有:

69%未使用的 CPU18%未使用內(nèi)存

通過使用 KRR 調(diào)整容器大小,你可以平均節(jié)省 69% 的云成本。

如果你使用 Robusta SaaS,從v0.10.15開始回集成 KRR,你可以查看所有建議(也包括以前的建議),按集群、命名空間或名稱過濾和排序它們。

工作原理

指標(biāo)收集

Robusta KRR 使用以下 Prometheus 查詢來收集使用數(shù)據(jù):

CPU 使用:sum(irate(container_cpu_usage_seconds_total{{namespace=”{object.namespace}”, pod=”{pod}”, cnotallow=”{object.container}”}}[{step}]))。內(nèi)存使用:sum(container_memory_working_set_bytes{job=”kubelet”, metrics_path=”/metrics/cadvisor”, image!=””, namespace=”{object.namespace}”, pod=”{pod}”, cnotallow=”{object.container}”})。

算法

默認(rèn)情況下,KRR 使用一個簡單的策略來計算資源推薦。它的計算方法如下(確切的數(shù)字可以在 CLI 參數(shù)中自定義):

對于 CPU,將請求設(shè)置為第 99 個百分位數(shù),并且沒有限制。這意味著,在 99%的情況下,您的 CPU 請求是足夠的。對于剩余的 1%,我們沒有設(shè)置限制。這意味著您的 Pod 可以突發(fā)并使用節(jié)點上可用的任何 CPU – 例如其他 Pod 請求但現(xiàn)在未使用的 CPU。對于內(nèi)存,使用過去一周內(nèi)最大值并添加 5%緩沖區(qū)。

安裝使用

MacOS/Linux 用戶可以使用 brew 進(jìn)行一鍵安裝:

brew tap robusta-dev/homebrew-krrbrew install krr

安裝完成后可以執(zhí)行下面的命令來檢查是否安裝成功:

krr --help # 第一次可能會花較長時間

如果想要手動進(jìn)行安裝,則首先確保在你的機(jī)器上安裝了 Python 3.9 或以上版本。然后 Clone 代碼:

git clone https://github.com/robusta-dev/krrcd krr

安裝依賴:

pip install -r requirements.txt

最后,運行下面的命令來運行工具:

python krr.py --help

請注意,使用源代碼需要您作為 python 腳本運行,當(dāng)使用 brew 安裝時允許運行 krr。以上所有示例都將運行命令顯示為krr …,如果您使用的是手動安裝,請將其替換為python krr.py …。

安裝完成后就可以來使用 KRR 工具了,比如可以運行一個簡單的策略:

krr simple

如果你只需要特定的命名空間(default和ingress-nginx):

krr simple -n default -n ingress-nginx

默認(rèn)情況下,krr 將在當(dāng)前上下文中運行,如果你想在不同的上下文中運行它:

krr simple -c my-cluster-1 -c my-cluster-2

如果想獲得 JSON 格式的輸出(需要–logtostderr,這樣就不會將日志轉(zhuǎn)到結(jié)果文件):

krr simple --logtostderr -f json > result.json

如果你想獲得 YAML 格式的輸出:

krr simple --logtostderr -f yaml > result.yaml

如果您想查看其他調(diào)試日志:

krr simple -v

關(guān)于策略設(shè)置的更多信息,可以通過以下方式找到:

krr simple --help

默認(rèn)情況下,KRR 將嘗試通過掃描下面的這些標(biāo)簽來自動發(fā)現(xiàn)正在運行的 Prometheus:

"app=kube-prometheus-stack-prometheus""app=prometheus,compnotallow=server""app=prometheus-server""app=prometheus-operator-prometheus""app=prometheus-msteams""app=rancher-monitoring-prometheus""app=prometheus-prometheus"

如果這些標(biāo)簽都沒有找到 Prometheus,則將收到錯誤消息,那么就必須顯式傳遞 url 了(使用-p標(biāo)志)。

如果你的 prometheus 沒有自動連接,我們可以使用kubectl port-forward手動轉(zhuǎn)發(fā) Prometheus。

例如有一個名為kube-prometheus-st-prometheus-0的 Prometheus Pod,則我們可以下面的命令對其進(jìn)行端口轉(zhuǎn)發(fā):

kubectl port-forward pod/kube-prometheus-st-prometheus-0 9090

然后,打開另一個終端并在其中運行krr,給出一個顯式的 prometheus url:

krr simple -p http://127.0.0.1:9090

此外我們還可以根據(jù)自己的需求來創(chuàng)建自定義的策略,比如下面的代碼就是創(chuàng)建一個自定義的策略:

# This is an example on how to create your own custom strategyimport pydantic as pdimport robusta_krrfrom robusta_krr.api.models import HistoryData, K8sObjectData, ResourceRecommendation, ResourceType, RunResultfrom robusta_krr.api.strategies import BaseStrategy, StrategySettings# Providing description to the settings will make it available in the CLI helpclass CustomStrategySettings(StrategySettings):    param_1: float = pd.Field(99, gt=0, descriptinotallow="First example parameter")    param_2: float = pd.Field(105_000, gt=0, descriptinotallow="Second example parameter")class CustomStrategy(BaseStrategy[CustomStrategySettings]):    """    A custom strategy that uses the provided parameters for CPU and memory.    Made only in order to demonstrate how to create a custom strategy.    """    def run(self, history_data: HistoryData, object_data: K8sObjectData) -> RunResult:        return {            ResourceType.CPU: ResourceRecommendation(request=self.settings.param_1, limit=None),            ResourceType.Memory: ResourceRecommendation(request=self.settings.param_2, limit=self.settings.param_2),        }# Running this file will register the strategy and make it available to the CLI# Run it as `python ./custom_strategy.py my_strategy`if __name__ == "__main__":    robusta_krr.run()

GitHub 地址:https://github.com/robusta-dev/krr

關(guān)鍵詞:

推薦內(nèi)容