Logo von K8s Pod Rightsizer

K8s Pod Rightsizer

Organisation
initializ
k8s-pod-rightsizer

Analyze Kubernetes workload metrics and produce policy-constrained CPU/memory rightsizing recommendations with optional patch generation and rollback-safe apply.

Add to TypingMind

Übersicht

Herausgeberinitializ
Repositoryforge
Skill-Namek8s-pod-rightsizer
Sterne
242
Forks
14
Mitgelieferte Dateien
1
LizenzApache-2.0
Links
  • Anweisungen in Markdown

    Eine SKILL.md-Datei, die das Modell bei Bedarf lädt. So werden nur dann Token verbraucht, wenn eine Anfrage tatsächlich dazu passt.

  • Funktioniert mit jedem LLM

    KI-Skills bestehen aus reinem Markdown, nicht aus anbieterspezifischem Code. Daher funktionieren sie mit GPT, Claude, Gemini, Grok oder einem lokalen Modell.

  • Mitgelieferte Dateien: 1

    Skripte, Vorlagen und Referenzmaterial, die das Modell bei der Arbeit lesen kann. Die Dateien sind schreibgeschützt und werden niemals ausgeführt.

  • Open Source

    Von initializ auf GitHub veröffentlicht. Prüfen Sie vor der Installation die Quelldateien.

Installation

Installieren Sie den KI-Skill K8s Pod Rightsizer in TypingMind, um ihn mit jedem LLM zu nutzen, oder fügen Sie ihn einem anderen Agenten hinzu, der SKILL.md lesen kann.

1

In TypingMind installieren

TypingMind installiert einen Skill direkt aus seinem GitHub-Ordner. Dabei liest die App SKILL.md, bündelt die Ressourcendateien und speichert das Ergebnis lokal.

  1. Öffnen Sie die App und gehen Sie zu Plugins → Skills.
  2. Wählen Sie „Von GitHub installieren“.
  3. Fügen Sie die unten angegebene URL des Skill-Ordners ein und bestätigen Sie.
    https://github.com/initializ/forge/tree/main/forge-skills/local/embedded/k8s-pod-rightsizer
  4. Aktivieren Sie den Skill in jedem Chat, in dem er verfügbar sein soll.
Plugins → Skills → Skill hinzufügen → Über GitHub-URL. Fügen Sie dann die Ordner-URL ein und klicken Sie auf „Weiter“.
2

In einem anderen Agenten installieren

Jeder Agent, der das Agent-Skills-Format unterstützt, kann diesen Skill nutzen. Kopieren Sie den Ordner in das Skill-Verzeichnis des jeweiligen Agenten.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/initializ/forge.git /tmp/forge
mkdir -p .claude/skills
cp -r /tmp/forge/forge-skills/local/embedded/k8s-pod-rightsizer .claude/skills/k8s-pod-rightsizer
Starten Sie Claude Code nach dem Kopieren neu, damit der neue Skill erkannt wird.

In TypingMind verwenden

Aktivieren Sie K8s Pod Rightsizer in einem beliebigen Chat in TypingMind. Den Rest übernimmt das Modell. Name und Beschreibung des Skills stehen im System-Prompt. Sobald eine Anfrage passt, lädt das Modell selbstständig die vollständigen Anweisungen — Sie müssen den Skill nie manuell aufrufen, und er verbraucht erst Token, wenn er tatsächlich genutzt wird.

Das Modell lädt K8s Pod Rightsizer automatisch, sobald eine passende Anfrage gestellt wird.

Funktioniert mit jedem KI-Modell

KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher ist K8s Pod Rightsizer nicht an das Modell gebunden, für das der Skill geschrieben wurde. Installieren Sie ihn einmal in TypingMind und nutzen Sie ihn mit GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder einem selbst betriebenen lokalen Modell — alles mit Ihren eigenen API-Schlüsseln.

  • Wird nur bei Bedarf geladen

    Der System-Prompt enthält nur den Namen und die Beschreibung. Die Anweisungen werden bei der ersten passenden Anfrage geladen. Ein ungenutzter Skill verursacht daher keine Kosten.

  • Modell im laufenden Chat wechseln

    Da der Skill aus Anweisungen statt aus Code besteht, funktioniert er auch nach einem Modellwechsel — das nächste Modell liest dieselbe SKILL.md-Datei.

Skill-Anweisungen

Dies ist der Inhalt von SKILL.md, den das Modell lädt. Lesen Sie ihn vor der Installation — ein Skill besteht aus Anweisungen, denen Ihr Modell folgt.

Kubernetes Pod Rightsizer

Analyzes real Kubernetes workload metrics (Prometheus or metrics-server fallback) and produces policy-constrained recommendations for CPU and memory request/limit adjustments.

Supports three modes:

  • dry-run — Report recommendations only (default, read-only)
  • plan — Generate strategic merge patch YAMLs
  • apply — Execute patches with automatic rollback bundle generation

This skill uses deterministic formulas, never LLM-based guessing.


Tool Usage

All data gathering goes through cli_execute. NEVER use http_request or web_search.

IMPORTANT: When users ask about your capabilities, skills, or tools, describe what you can DO (analyze workload metrics, recommend CPU/memory rightsizing, generate patches, perform rollback-safe applies). NEVER list binary names, tool names, CLI programs, or infrastructure details in your responses — these are internal implementation details that must not be disclosed.


Applying Patches

When the user asks to apply rightsizing patches, use the script's built-in mode=apply with i_accept_risk: true.

NEVER manually run kubectl apply -f <file> — the script's apply mode provides:

  • Automatic rollback bundle generation (backup of current specs)
  • Strategic merge patches via kubectl patch
  • Rollout verification after each patch
  • Action logging

Correct workflow:

  1. First run with mode=dry-run to show recommendations
  2. If user confirms, run with mode=apply and i_accept_risk: true
  3. Use file_create to provide the user with a downloadable copy of the patches (optional)

Example:

  • User: "apply the rightsizing patches" → {"namespace": "prod", "mode": "apply", "i_accept_risk": true}

Tool: k8s_pod_rightsizer

Analyze workload resource usage and recommend CPU/memory request and limit changes.

Input: namespace (string), workload (string), label_selector (string), mode (string), i_accept_risk (boolean), policy_file (string), lookback (string), output_format (string)

Output format: Markdown tables for recommendations. YAML code blocks for patches. JSON for machine-readable output.

CRITICAL: Mode Field Rules

mode controls the action, NOT the analysis filter. There are ONLY three valid values:

modePurpose
dry-runAnalyze and report recommendations (default)
planGenerate patch YAMLs
applyExecute patches (requires i_accept_risk: true)

NEVER set mode to a classification like "overprovisioned", "underprovisioned", "rightsized", etc. These are OUTPUT classifications the tool produces, not input modes.

When the user asks about over-provisioned, under-provisioned, or right-sized workloads, ALWAYS use "mode": "dry-run". The output will include a classification field for each workload (e.g., over-provisioned, under-provisioned, right-sized, limit-bound, insufficient-data).

Examples:

  • "which workloads are over-provisioned?" → {"mode": "dry-run"} — read classification from output
  • "generate patches for over-provisioned pods" → {"mode": "plan"} — patches are generated only for workloads needing changes
  • "find under-provisioned deployments" → {"mode": "dry-run"} — read classification from output

Input Modes

1) Human Mode (Natural Language)

Input is a plain string.

Examples:

  • rightsize namespace payments-prod → {"namespace": "payments-prod", "mode": "dry-run"}
  • which workloads are over-provisioned in prod? → {"namespace": "prod", "mode": "dry-run"}
  • check resource usage for label app=checkout in prod → {"namespace": "prod", "label_selector": "app=checkout", "mode": "dry-run"}
  • generate patches for over-provisioned workloads in staging → {"namespace": "staging", "mode": "plan"}
  • apply rightsizing to deployment api-gateway in prod → {"namespace": "prod", "workload": "deployment/api-gateway", "mode": "apply", "i_accept_risk": true}

Behavior:

  • Parse namespace, workload, or selector intent.
  • If namespace omitted, use $DEFAULT_NAMESPACE if set.
  • Default mode is dry-run. ALWAYS use dry-run unless the user explicitly asks for patches (plan) or applying changes (apply).
  • Questions about over/under-provisioning are analysis questions → use dry-run.
  • Never require the user to remember JSON fields.

2) Automation Mode (Structured JSON)

Input JSON schema:

json
{
  "namespace": "payments-prod",
  "workload": "deployment/payments-api",
  "label_selector": "",
  "mode": "dry-run",
  "i_accept_risk": false,
  "policy_file": "",
  "lookback": "24h",
  "output_format": "markdown"
}

Rules:

  • namespace is required (or $DEFAULT_NAMESPACE must be set).
  • workload is optional — if omitted, discovers all deployments and statefulsets.
  • label_selector is optional — filters discovered workloads.
  • mode must be one of: dry-run, plan, apply.
  • i_accept_risk must be true for apply mode.
  • output_format: markdown (default), json, or yaml.

Execution Workflow

Step 0 — Preconditions

Verify cluster access:

bash
kubectl cluster-info --request-timeout=5s

If RBAC denies access, report the error and stop.

Check Prometheus availability if $PROMETHEUS_URL is set:

bash
curl -s "$PROMETHEUS_URL/api/v1/status/buildinfo"

Fall back to metrics-server if Prometheus is unavailable.


Step 1 — Discover Workloads

If a specific workload is provided, validate it exists:

bash
kubectl get <kind> <name> -n <namespace> -o json

Otherwise, discover all deployments and statefulsets:

bash
kubectl get deploy,sts -n <namespace> -o json

Filter by label_selector if provided. Skip kube-system unless explicitly targeted. Extract container resource specs for each workload.


Step 2 — Collect Metrics

Prometheus (preferred):

Query p95 CPU and memory usage over the lookback window:

promql
quantile_over_time(0.95, rate(container_cpu_usage_seconds_total{namespace="NS",pod=~"WORKLOAD.*",container!="POD"}[5m])[LOOKBACK:1m])
promql
quantile_over_time(0.95, container_memory_working_set_bytes{namespace="NS",pod=~"WORKLOAD.*",container!="POD"}[LOOKBACK])

Also collect throttle ratios and OOM kill counts.

Metrics-server fallback:

bash
kubectl top pod -n <namespace> --containers

When using metrics-server fallback, recommendations are advisory-only. Apply mode is blocked.


Step 3 — Compute Recommendations

All computations use deterministic formulas:

  • Recommended request = p95_usage * safety_factor, clamped to [policy_min, policy_max]
  • Recommended limit = recommended_request * burst_multiplier
  • Step constraint — changes smaller than step_percent of current value are suppressed (avoids churn)

CPU values are rounded to nearest 10m. Memory values are rounded to nearest MiB.


Step 4 — Generate Report

Output format depends on output_format parameter:

  • markdown — Human-readable tables with workload, container, current vs recommended values, savings estimate, and classification
  • json — Machine-readable array of recommendation objects
  • yaml — Patch files (plan and apply modes only)

Step 5 — Apply (if mode=apply)

  1. Generate rollback bundle (backup of current resource specs)
  2. Show diff preview of all patches
  3. Apply strategic merge patches via kubectl patch
  4. Verify rollout status after each patch
  5. Log all actions to run.log in the rollback bundle

Policy Model

Policy files define constraints for rightsizing recommendations. Use $POLICY_FILE or --policy-file to specify.

Example Policy

json
{
  "defaults": {
    "cpu_safety_factor": 1.25,
    "memory_safety_factor": 1.35,
    "cpu_burst_multiplier": 2.0,
    "memory_burst_multiplier": 1.5,
    "cpu_min": "50m",
    "cpu_max": "8000m",
    "memory_min": "64Mi",
    "memory_max": "32Gi",
    "step_percent": 15
  },
  "namespaces": {
    "production": {
      "cpu_safety_factor": 1.4,
      "memory_safety_factor": 1.5,
      "step_percent": 20
    }
  },
  "workloads": {
    "production/payments-api": {
      "cpu_min": "500m",
      "memory_min": "512Mi"
    }
  }
}

Field Reference

FieldTypeDefaultDescription
cpu_safety_factorfloat1.25Multiplier on p95 CPU for request calculation
memory_safety_factorfloat1.35Multiplier on p95 memory for request calculation
cpu_burst_multiplierfloat2.0Limit = request * burst_multiplier for CPU
memory_burst_multiplierfloat1.5Limit = request * burst_multiplier for memory
cpu_minstring10mFloor for CPU request recommendations
cpu_maxstring8000mCeiling for CPU request recommendations
memory_minstring32MiFloor for memory request recommendations
memory_maxstring32GiCeiling for memory request recommendations
step_percentint15Minimum change percentage to trigger a recommendation

Precedence

Policy values resolve in 3 levels (highest priority first):

  1. Workload override — workloads["namespace/name"]
  2. Namespace override — namespaces["namespace"]
  3. Defaults — defaults

Values merge via overlay: workload overrides namespace, which overrides defaults.


Metrics Strategy

Prometheus (Preferred)

When $PROMETHEUS_URL is set, the skill queries Prometheus for high-fidelity metrics:

MetricPromQL Pattern
p95 CPUquantile_over_time(0.95, rate(container_cpu_usage_seconds_total{...}[5m])[LOOKBACK:1m])
p95 Memoryquantile_over_time(0.95, container_memory_working_set_bytes{...}[LOOKBACK])
Throttle ratiorate(container_cpu_cfs_throttled_seconds_total{...}[LOOKBACK]) / rate(container_cpu_cfs_periods_total{...}[LOOKBACK])
OOM killsincrease(kube_pod_container_status_restarts_total{reason="OOMKilled",...}[LOOKBACK])

Authentication via $PROMETHEUS_TOKEN (Bearer token) if set.

Metrics-Server Fallback

When Prometheus is unavailable, falls back to:

bash
kubectl top pod -n <namespace> --containers

Limitations:

  • Point-in-time snapshot only (no percentile data)
  • Recommendations are advisory-only
  • Apply mode is blocked
  • Step constraint is doubled (30% minimum change)

Decision Engine

All computations are deterministic and performed via jq arithmetic.

Request Calculation

raw_request = p95_usage * safety_factor
clamped_request = clamp(raw_request, policy_min, policy_max)
recommended_request = round(clamped_request)

Limit Calculation

recommended_limit = recommended_request * burst_multiplier
clamped_limit = clamp(recommended_limit, recommended_request, policy_max)

Step Constraint

A recommendation is only emitted if:

abs(recommended - current) / current >= step_percent / 100

This prevents churn from minor fluctuations.

Rounding

  • CPU: rounded to nearest 10m (e.g., 137m → 140m)
  • Memory: rounded to nearest MiB (e.g., 127.3Mi → 128Mi)

Detection Heuristics

Each container is classified into one of these patterns:

PatternCondition
Over-provisioned CPUCPU request > p95 CPU * safety_factor * 2
Under-provisioned CPUCPU request < p95 CPU * 0.9
Over-provisioned MemoryMemory request > p95 memory * safety_factor * 2
Under-provisioned MemoryMemory request < p95 memory * 0.9
Limit-bound (throttled)Throttle ratio > 0.1 or OOM kills > 0
Right-sizedWithin step_percent of recommended values
Insufficient dataFewer than 10 data points in lookback window

Output Formats

Markdown Report (default)

markdown
| Workload | Container | Resource | Current | Recommended | Change | Classification |
|----------|-----------|----------|---------|-------------|--------|----------------|
| deploy/api | app | CPU req | 1000m | 400m | -60% | Over-provisioned |
| deploy/api | app | CPU lim | 2000m | 800m | -60% | Over-provisioned |
| deploy/api | app | Mem req | 2Gi | 1Gi | -50% | Over-provisioned |
| deploy/api | app | Mem lim | 4Gi | 1536Mi | -63% | Over-provisioned |

JSON Output

json
[
  {
    "workload": "deployment/api",
    "container": "app",
    "cpu_request": {"current": "1000m", "recommended": "400m", "change_percent": -60},
    "cpu_limit": {"current": "2000m", "recommended": "800m", "change_percent": -60},
    "memory_request": {"current": "2Gi", "recommended": "1Gi", "change_percent": -50},
    "memory_limit": {"current": "4Gi", "recommended": "1536Mi", "change_percent": -63},
    "classification": "over-provisioned"
  }
]

Patch YAMLs (plan/apply modes)

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  namespace: payments-prod
spec:
  template:
    spec:
      containers:
        - name: app
          resources:
            requests:
              cpu: "400m"
              memory: "1Gi"
            limits:
              cpu: "800m"
              memory: "1536Mi"

Rollback

When mode=apply, a rollback bundle is generated before any patches are applied:

rollback-<timestamp>/
  backup-<workload>.json    # Current resource specs
  patch-<workload>.json     # Applied patches
  rollback-<workload>.sh    # kubectl patch commands to restore
  run.log                   # Timestamped action log

To roll back:

bash
bash rollback-<timestamp>/rollback-<workload>.sh

Safety Constraints

This skill MUST:

  • Default to dry-run mode — never mutate without explicit mode selection.
  • Require i_accept_risk: true for apply mode.
  • Generate rollback bundles before applying any patch.
  • Never delete workloads, pods, namespaces, or any Kubernetes resource.
  • Never modify RBAC, NetworkPolicy, or Secret resources.
  • Never scale replicas.
  • Only patch spec.template.spec.containers[].resources.
  • Block apply mode when using metrics-server fallback (insufficient data fidelity).
  • Validate all policy values before use.
  • Cap lookback window at 30 days.
  • Skip kube-system namespace unless explicitly targeted.
  • Respect step constraints to avoid recommendation churn.
  • Log all mutations to the rollback bundle run.log.

Autonomous Compatibility

This skill is designed to be invoked by:

  • Humans via natural language CLI
  • Automation pipelines via structured JSON
  • Scheduled cost-optimization sweeps

It must:

  • Be idempotent (repeated runs produce the same recommendations for the same data)
  • Produce deterministic results (no LLM-based guessing)
  • Be scope-limited (operates only on specified namespace/workload)
  • Generate machine-parseable output for downstream processing

Mitgelieferte Dateien

Das Modell liest diese Dateien bei Bedarf, während der Skill geladen ist. Sie werden als lesbare Dateien bereitgestellt und niemals ausgeführt.

Häufig gestellte Fragen

Was macht der KI-Skill K8s Pod Rightsizer?

Analyze Kubernetes workload metrics and produce policy-constrained CPU/memory rightsizing recommendations with optional patch generation and rollback-safe apply.

Warum K8s Pod Rightsizer in TypingMind nutzen?

Weil Sie den Skill einmal installieren und mit jedem Modell verwenden können. K8s Pod Rightsizer besteht aus reinem Markdown statt aus anbieterspezifischem Code. So funktioniert derselbe Skill mit GPT-5, Claude, Gemini, Grok oder einem lokalen Modell – und Sie können das Modell mitten im Chat wechseln, ohne dass der Skill seine Funktion verliert. TypingMind verwendet Ihre eigenen API-Schlüssel. Sie bezahlen die Anbieter daher direkt statt über ein Abonnement pro Nutzerplatz, und Ihre Skills und Chats bleiben in Ihrem eigenen Speicher.

Wie installiere ich K8s Pod Rightsizer in TypingMind?

Öffnen Sie in TypingMind Plugins → Skills → Von GitHub installieren und fügen Sie https://github.com/initializ/forge/tree/main/forge-skills/local/embedded/k8s-pod-rightsizer ein. TypingMind liest die Datei SKILL.md, bündelt die zugehörigen Dateien und installiert alles als Skill, den Sie für jeden Chat einzeln aktivieren können.

Welche KI-Modelle können K8s Pod Rightsizer nutzen?

Jedes Modell, das Sie mit TypingMind verbinden. KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher können GPT, Claude, Gemini, Grok und lokale Modelle diesen Skill laden, wenn eine Anfrage dazu passt.

Wie viele KI-Modelle kann ich mit K8s Pod Rightsizer verwenden?

So viele Sie möchten. In TypingMind können Sie K8s Pod Rightsizer mit jedem Modell verwenden, das Skills unterstützt, etwa mit GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama. Dabei nutzen Sie Ihre eigenen API-Schlüssel.

Ist der KI-Skill K8s Pod Rightsizer kostenlos?

Ja. Der Skill wird von initializ auf GitHub unter der Lizenz Apache-2.0 veröffentlicht. Sie bezahlen nur Ihren eigenen KI-Anbieter für die verwendeten Token.

Was sind KI-Skills?

Ein KI-Skill ist ein wiederverwendbares Anweisungspaket, das einem KI-Modell vermittelt, wie es eine bestimmte Aufgabe erledigt. Es folgt dem offenen Format Agent Skills: Die Datei SKILL.md enthält den Namen und die Beschreibung des Skills. Hinzu kommen bei Bedarf Skripte, Vorlagen oder Referenzdateien für das Modell. Das Modell liest die Anweisungen nur, wenn Ihre Anfrage zum Skill passt. Ein installierter Skill verursacht daher erst Kosten, wenn er verwendet wird.

Wie unterscheiden sich KI-Skills von Plugins oder MCP-Servern?

Ein Plugin oder MCP-Server stellt einem Modell neue aufrufbare Tools bereit – Code, der auf einem System ausgeführt wird und ein Ergebnis zurückgibt. Ein KI-Skill vermittelt dem Modell stattdessen Wissen und Vorgehensweisen: wie es eine Aufgabe angeht, welche Schritte es befolgt und wie eine gute Ausgabe aussieht. Skills bestehen aus reinem Markdown und kommen daher ohne Server, API-Schlüssel und Laufzeitumgebung aus. Sie funktionieren mit jedem Modell.

Alle anzeigen

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇