jpskill.com
🛠️ 開発・MCP コミュニティ

k8s-cost-optimizer

Kubernetesクラスタのリソース使用状況を分析し、無駄を特定して適切なリソース配分を提案することで、コスト削減や効率化に貢献するSkill。

📜 元の英語説明(参考)

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.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Kubernetesクラスタのリソース使用状況を分析し、無駄を特定して適切なリソース配分を提案することで、コスト削減や効率化に貢献するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o k8s-cost-optimizer.zip https://jpskill.com/download/15032.zip && unzip -o k8s-cost-optimizer.zip && rm k8s-cost-optimizer.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15032.zip -OutFile "$d\k8s-cost-optimizer.zip"; Expand-Archive "$d\k8s-cost-optimizer.zip" -DestinationPath $d -Force; ri "$d\k8s-cost-optimizer.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して k8s-cost-optimizer.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → k8s-cost-optimizer フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Kubernetes Cost Optimizer

概要

この Skill は、metrics-server からの実際の使用量と要求された CPU/メモリを比較することで、Kubernetes クラスタのリソース非効率性を監査します。ゾンビデプロイメント、過剰プロビジョニングされたワークロードを特定し、安全バッファ付きで適切なサイズに変更するための kustomize 互換パッチを生成します。

手順

ステップ 1: クラスタアクセスとメトリクスの可用性の確認

kubectl cluster-infokubectl top nodes を実行して、接続性と metrics-server が実行されていることを確認します。metrics-server が利用できない場合は、ユーザーに通知し、最初にインストールすることを提案します。

ステップ 2: リソースデータの収集

各 namespace (またはユーザー指定の namespace) に対して:

# すべての Pod のリソース要求/制限を取得
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
  }]
}]'

# 実際の使用量を取得
kubectl top pods --all-namespaces --no-headers

ステップ 3: 効率比率の計算

各デプロイメントについて、以下を計算します。

  • Efficiency = actual_usage / requested × 100
  • Waste = 100 - efficiency
  • Monthly cost estimate = (requested_cpu × node_cost_per_cpu) + (requested_mem × node_cost_per_gi)

ユーザーが指定しない場合は、以下の参照価格を使用します。

  • On-demand: ~$0.0425/vCPU-hour, ~$0.0057/GiB-hour (AWS us-east-1 m5 family)
  • 月額に換算: 時間あたりを 730 倍します

ステップ 4: ゾンビワークロードの特定

以下の条件に一致するデプロイメントにフラグを立てます。

  • CPU 使用量が 7 日以上 < 1m (1 millicore) である
  • Pod の再起動回数が 0 で、レプリカが実行中である
  • Namespace が staging/dev/preview パターンに一致する

ステップ 5: 適切なサイズ変更の推奨事項の生成

過剰プロビジョニングされたワークロードごとに:

  1. 利用可能な履歴(理想的には 14 日間)にわたって p99 使用量を取得します
  2. 設定可能なヘッドルームバッファを追加します(デフォルト:30%)
  3. requests = p99 + buffer、limits = requests × 1.5 を設定します
  4. kustomize パッチまたはプレーンな YAML 差分として出力します

ステップ 6: サマリーレポートの作成

以下の項目を示すテーブルをフォーマットします。

  • 推定月間節約額でソートされた、最も無駄の多い上位の違反者
  • クラスタ全体の無駄の割合
  • 予測される年間節約額
  • 各推奨事項のリスク評価(低/中/高)

例 1: Namespace の監査

ユーザープロンプト:

api-services namespace のリソースの無駄を監査する

エージェントの出力:

リソース監査: api-services namespace
───────────────────────────────────────

デプロイメント          レプリカ  CPU Req→Used   Mem Req→Used    効率         推定無駄
user-auth           3         500m→120m      1Gi→340Mi       26%         $85/月
order-processor     2         1000m→650m     2Gi→1.4Gi       68%         $31/月
email-worker        2         250m→15m       512Mi→80Mi      8%          $42/月

推奨事項:
1. email-worker: レプリカを 1 に減らし、requests を cpu:50m/mem:150Mi に設定 → $42/月節約
2. user-auth: requests を cpu:180m/mem:500Mi に設定 → $68/月節約
3. order-processor: requests は妥当、cpu:850m にわずかに削減 → $12/月節約

潜在的な総節約額: $122/月 ($1,464/年)

例 2: ゾンビ検出

ユーザープロンプト:

すべての namespace で未使用のデプロイメントを見つける

エージェントの出力:

ゾンビワークロードが検出されました
─────────────────────────

Namespace: staging
  ✗ feature-auth-v2      2 レプリカ  CPU: 0m  最終デプロイ: 2025-09-14  → $28/月の無駄
  ✗ hotfix-payment-flow   1 レプリカ   CPU: 0m  最終デプロイ: 2025-10-02  → $14/月の無駄
  ✗ demo-dashboard        3 レプリカ  CPU: 0m  最終デプロイ: 2025-07-28  → $42/月の無駄

Namespace: dev
  ✗ test-migration        1 レプリカ   CPU: 0m  最終デプロイ: 2025-11-18  → $14/月の無駄

推奨されるクリーンアップ:
  kubectl delete deployment feature-auth-v2 hotfix-payment-flow demo-dashboard -n staging
  kubectl delete deployment test-migration -n dev

ゾンビの総コスト: $98/月

ガイドライン

  • 変更を自動的に適用しないでください — 常に人間のレビューのために推奨事項を提示してください
  • 安全バッファは重要です — デフォルトの 30% のヘッドルームは、適切なサイズ変更後の OOMKills を防ぎます
  • 節約額で優先順位を付けます — ユーザーが重要な場所に労力を集中できるように、最大の勝利を最初に示します
  • トラフィックパターンを考慮します — 使用状況データが 7 日未満であるか、ピーク期間を逃している場合は警告します
  • HPA を検討します — デプロイメントに HorizontalPodAutoscaler がある場合、適切なサイズ変更要求がスケーリングしきい値に影響することに注意してください
  • Staging vs production — staging の推奨事項についてはより積極的になり、production についてはより保守的になります
  • コストの見積もりは概算です — インスタンスタイプの仮定に注意し、ユーザーに実際の価格で確認するように提案します
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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.

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
kubectl top pods --all-namespaces --no-headers

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)

Use these reference prices if the user doesn't specify:

  • On-demand: ~$0.0425/vCPU-hour, ~$0.0057/GiB-hour (AWS us-east-1 m5 family)
  • Convert to monthly: multiply hourly by 730

Step 4: Identify Zombie Workloads

Flag deployments where:

  • CPU usage is < 1m (1 millicore) for 7+ days
  • Pod restart count is 0 and replicas are running
  • Namespace matches staging/dev/preview patterns

Step 5: Generate Right-Sizing Recommendations

For each overprovisioned workload:

  1. Take the p99 usage over available history (ideally 14 days)
  2. Add a configurable headroom buffer (default: 30%)
  3. Set requests = p99 + buffer, limits = requests × 1.5
  4. 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-migration -n dev

Total zombie cost: $98/month

Guidelines

  • Never auto-apply changes — always present recommendations for human review
  • Safety buffer is critical — default 30% headroom prevents OOMKills after right-sizing
  • Prioritize by savings — show the biggest wins first so users focus effort where it matters
  • Account for traffic patterns — warn if usage data covers less than 7 days or misses peak periods
  • Consider HPA — if a deployment has a HorizontalPodAutoscaler, note that right-sizing requests affects scaling thresholds
  • Staging vs production — be more aggressive with staging recommendations, more conservative with production
  • Cost estimates are approximate — note the instance type assumptions and suggest the user verify with their actual pricing