@@ -154,6 +154,224 @@ To prevent the KRR job from OOMKill (Out of Memory), you can configure the memor
154154
155155 By default, the memory request and limit are set to ``2Gi ``. Modify these values according to your requirements.
156156
157+ KRR API
158+ ======================================
159+
160+ You can retrieve KRR recommendations programmatically using the Robusta API. This allows you to integrate resource recommendations into your own tools and workflows.
161+
162+
163+ Authentication
164+ ---------------------
165+
166+ The KRR API requires authentication via API key.
167+
168+ To create your key, on the ``Robusta Platform ``, go to the ``settings `` page, and choose the ``API keys `` tab.
169+
170+ Click ``New API Key ``. Choose a name for your key, and check the ``KRR Read `` capability.
171+
172+ .. image :: /images/krr-api-key.png
173+ :width: 500px
174+
175+ GET /api/krr-recommendations
176+ ----------------------------------------------------
177+
178+ Retrieves KRR resource recommendations for a specific cluster and namespace.
179+
180+ **Query Parameters **
181+
182+ .. list-table ::
183+ :widths: 20 15 40 15
184+ :header-rows: 1
185+
186+ * - Parameter
187+ - Type
188+ - Description
189+ - Required
190+ * - ``cluster ``
191+ - STRING
192+ - The cluster name to get recommendations for
193+ - Yes
194+ * - ``namespace ``
195+ - STRING
196+ - The namespace to get recommendations for (use "*" for all namespaces)
197+ - Yes
198+ * - ``limit ``
199+ - INTEGER
200+ - Maximum number of recommendations to return (default: 100)
201+ - No
202+
203+ **Request Headers **
204+
205+ .. list-table ::
206+ :widths: 30 70
207+ :header-rows: 1
208+
209+ * - Header
210+ - Value
211+ * - ``Authorization ``
212+ - ``Bearer <your-api-key> ``
213+ * - ``Content-Type ``
214+ - ``application/json ``
215+
216+ **Example Request **
217+
218+ .. code-block :: bash
219+
220+ curl -X GET " https://api.robusta.dev/api/krr-recommendations?cluster=my-cluster&namespace=default&limit=50" \
221+ -H " Authorization: Bearer YOUR_API_KEY" \
222+ -H " Content-Type: application/json"
223+
224+ **Success Response (200 OK) **
225+
226+ .. code-block :: json
227+
228+ {
229+ "scans" : [
230+ {
231+ "object" : {
232+ "cluster" : " my-cluster" ,
233+ "name" : " nginx-deployment" ,
234+ "container" : " nginx" ,
235+ "namespace" : " default" ,
236+ "kind" : " Deployment" ,
237+ "allocations" : {
238+ "requests" : {
239+ "cpu" : 0.1 ,
240+ "memory" : 128
241+ },
242+ "limits" : {
243+ "cpu" : 0.5 ,
244+ "memory" : 512
245+ }
246+ },
247+ "warnings" : [],
248+ "current_pod_count" : 3
249+ },
250+ "recommended" : {
251+ "requests" : {
252+ "cpu" : {
253+ "value" : 0.05 ,
254+ "severity" : " WARNING"
255+ },
256+ "memory" : {
257+ "value" : 64 ,
258+ "severity" : " OK"
259+ }
260+ },
261+ "limits" : {
262+ "cpu" : {
263+ "value" : 0.2 ,
264+ "severity" : " WARNING"
265+ },
266+ "memory" : {
267+ "value" : 256 ,
268+ "severity" : " OK"
269+ }
270+ },
271+ "info" : {
272+ "cpu" : " CPU usage is consistently low" ,
273+ "memory" : " Memory usage is within acceptable range"
274+ }
275+ },
276+ "severity" : " WARNING" ,
277+ "metrics" : {
278+ "cpu" : {
279+ "query" : " avg(container_cpu_usage_seconds_total)" ,
280+ "start_time" : " 2024-01-01T00:00:00Z" ,
281+ "end_time" : " 2024-01-07T00:00:00Z" ,
282+ "step" : " 1h"
283+ },
284+ "memory" : {
285+ "query" : " avg(container_memory_usage_bytes)" ,
286+ "start_time" : " 2024-01-01T00:00:00Z" ,
287+ "end_time" : " 2024-01-07T00:00:00Z" ,
288+ "step" : " 1h"
289+ }
290+ }
291+ }
292+ ],
293+ "score" : 75 ,
294+ "resources" : [" cpu" , " memory" ],
295+ "description" : " Resource recommendations based on 7-day usage analysis" ,
296+ "strategy" : {
297+ "name" : " simple" ,
298+ "settings" : {
299+ "history_duration" : 336 ,
300+ "cpu_percentile" : 99 ,
301+ "memory_buffer_percentage" : 15
302+ }
303+ }
304+ }
305+
306+ **Response Fields **
307+
308+ .. list-table ::
309+ :widths: 25 15 60
310+ :header-rows: 1
311+
312+ * - Field
313+ - Type
314+ - Description
315+ * - ``scans ``
316+ - ARRAY
317+ - Array of KRR scan results for workloads
318+ * - ``scans[].object.name ``
319+ - STRING
320+ - Name of the Kubernetes workload
321+ * - ``scans[].object.kind ``
322+ - STRING
323+ - Type of Kubernetes resource (Deployment, StatefulSet, etc.)
324+ * - ``scans[].object.namespace ``
325+ - STRING
326+ - Namespace of the workload
327+ * - ``scans[].object.container ``
328+ - STRING
329+ - Container name within the workload
330+ * - ``scans[].object.allocations ``
331+ - OBJECT
332+ - Current CPU/memory requests and limits
333+ * - ``scans[].recommended.requests ``
334+ - OBJECT
335+ - Recommended CPU/memory requests with severity
336+ * - ``scans[].recommended.limits ``
337+ - OBJECT
338+ - Recommended CPU/memory limits with severity
339+ * - ``scans[].severity ``
340+ - STRING
341+ - Overall severity: CRITICAL, WARNING, OK, GOOD, UNKNOWN
342+ * - ``score ``
343+ - INTEGER
344+ - Overall efficiency score (0-100)
345+ * - ``strategy ``
346+ - OBJECT
347+ - KRR strategy and settings used for recommendations
348+
349+ **Error Responses **
350+
351+ **401 Unauthorized **
352+
353+ .. code-block :: json
354+
355+ {
356+ "error" : " Invalid or missing API key"
357+ }
358+
359+ **400 Bad Request **
360+
361+ .. code-block :: json
362+
363+ {
364+ "error" : " Missing required parameter: cluster"
365+ }
366+
367+ **404 Not Found **
368+
369+ .. code-block :: json
370+
371+ {
372+ "error" : " Cluster 'my-cluster' not found or no data available"
373+ }
374+
157375 Reference
158376======================================
159377.. robusta-action :: playbooks.robusta_playbooks.krr.krr_scan on_schedule
0 commit comments