k8s-cost-optimizer
БесплатноБез исполняемых скриптовНе проверенAnalyzes Kubernetes cluster resource allocation versus actual usage to find waste and generate right-sizing recommendations. Use when someone asks about…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Kubernetes Cost Optimizer
Overview
This skill audits Kubernetes clusters for resource inefficiency by comparing requested CPU/memory against actual usage from metrics-server. It identifies zombie deployments, overprovisioned workloads, and generates kustomize-compatible patches for right-sizing with safety buffers.
Instructions
Step 1: Verify Cluster Access and Metrics Availability
Run kubectl cluster-info and kubectl top nodes to confirm connectivity and that metrics-server is running. If metrics-server is unavailable, inform the user and suggest installing it first (see the kubernetes-sigs/metrics-server install manifest or Helm chart). All steps here are read-only; only get and top are needed.
Step 2: Collect Resource Data
For each namespace (or user-specified namespaces):
# Get resource requests/limits for all pods
kubectl get pods --all-namespaces -o json | jq '[.items[] | {
namespace: .metadata.namespace,
pod: .metadata.name,
containers: [.spec.containers[] | {
name: .name,
cpu_request: .resources.requests.cpu,
cpu_limit: .resources.limits.cpu,
mem_request: .resources.requests.memory,
mem_limit: .resources.limits.memory
}]
}]'
# Get actual usage right now (a single point-in-time sample from metrics-server)
kubectl top pods --all-namespaces --containers --no-headers
kubectl top has no history, so it cannot give a p99. For a real baseline, query Prometheus over 7-14 days (container_cpu_usage_seconds_total rate and container_memory_working_set_bytes per container), or read recommendations from the Vertical Pod Autoscaler running with updateMode: "Off" (Goldilocks creates these VPAs per namespace and shows them in a dashboard). OpenCost gives allocation-based cost per namespace and workload.
Step 3: Calculate Efficiency Ratios
For each deployment, compute:
- Efficiency = actual_usage / requested × 100
- Waste = 100 - efficiency
- Monthly cost estimate = (requested_cpu × node_cost_per_cpu) + (requested_mem × node_cost_per_gi)
Derive unit prices from the user's real node price. If none is given, assume a rough split: half of the node's hourly price to CPU, half to memory. Example: m5.large (2 vCPU, 8 GiB) at about $0.096/hour on-demand in AWS us-east-1 gives ~$0.024/vCPU-hour and ~$0.006/GiB-hour. Convert to monthly by multiplying hourly by 730, and say these are estimates.
Step 4: Identify Zombie Workloads
Flag deployments where:
- CPU usage is < 1m (1 millicore) for 7+ days
- Pods are Running with no restarts but receive no traffic (check Service endpoints, ingress or request metrics)
- Namespace matches staging/dev/preview patterns
Step 5: Generate Right-Sizing Recommendations
For each overprovisioned workload:
- Take the p99 usage from Prometheus or the VPA recommendation (ideally 14 days, including peaks)
- Add a configurable headroom buffer (default: 30%)
- Set requests = p99 + buffer. Memory: set the limit equal to the request (memory is not compressible, exceeding it means OOMKill). CPU: prefer no limit, or a generous one, because tight CPU limits cause throttling
- Output as kustomize patches or plain YAML diffs
Step 6: Produce Summary Report
Format a table showing:
- Top waste offenders sorted by estimated monthly savings
- Total cluster waste percentage
- Projected annual savings
- Risk assessment (low/medium/high) for each recommendation
Examples
Example 1: Namespace Audit
User prompt:
Audit the api-services namespace for resource waste
Agent output:
Resource Audit: api-services namespace
───────────────────────────────────────
Deployment Replicas CPU Req→Used Mem Req→Used Efficiency Est. Waste
user-auth 3 500m→120m 1Gi→340Mi 26% $85/mo
order-processor 2 1000m→650m 2Gi→1.4Gi 68% $31/mo
email-worker 2 250m→15m 512Mi→80Mi 8% $42/mo
Recommendations:
1. email-worker: Reduce to 1 replica, set requests to cpu:50m/mem:150Mi → saves $42/mo
2. user-auth: Set requests to cpu:180m/mem:500Mi → saves $68/mo
3. order-processor: Requests are reasonable, minor trim to cpu:850m → saves $12/mo
Total potential savings: $122/month ($1,464/year)
Example 2: Zombie Detection
User prompt:
Find unused deployments across all namespaces
Agent output:
Zombie Workloads Detected
─────────────────────────
Namespace: staging
✗ feature-auth-v2 2 replicas CPU: 0m Last deploy: 2025-09-14 → $28/mo wasted
✗ hotfix-payment-flow 1 replica CPU: 0m Last deploy: 2025-10-02 → $14/mo wasted
✗ demo-dashboard 3 replicas CPU: 0m Last deploy: 2025-07-28 → $42/mo wasted
Namespace: dev
✗ test-migration 1 replica CPU: 0m Last deploy: 2025-11-18 → $14/mo wasted
Suggested cleanup:
kubectl delete deployment feature-auth-v2 hotfix-payment-flow demo-dashboard -n staging
kubectl delete deployment test-
Установить k8s-cost-optimizer в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл k8s-cost-optimizer?
Analyzes Kubernetes cluster resource allocation versus actual usage to find waste and generate right-sizing recommendations. Use when someone asks about Kubernetes costs, overprovisioned pods, resource requests/limits tuning, cluster efficiency, or cloud bill reduction for K8s workloads. Trigger words: k8s costs, pod resources, right-size, overprovisioned, resource waste, cluster optimization, CPU/memory requests.
Как установить скилл k8s-cost-optimizer?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл k8s-cost-optimizer запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
ci-review
The scan that the plugin's GitHub Action runs.
от Anthropicazure-static-web-apps
Helps create, configure, and deploy Azure Static Web Apps using the SWA CLI. Use when deploying static sites to Azure, setting up SWA local development…
от GitHubai-ready
Make any repo AI-ready — analyzes your codebase and generates AGENTS.md, copilot-instructions.md, CI workflows, issue templates, and more. Mines your PR…
от GitHubaws-cdk-python-setup
Setup and initialization guide for developing AWS CDK (Cloud Development Kit) applications in Python. This skill enables users to configure environment…
от GitHub