k8s-cost
Optimize Kubernetes costs through resource right-sizing, unused resource detection, and cluster efficiency analysis. Use for cost optimization, resource analysis, and capacity planning.
Best use case
k8s-cost is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Optimize Kubernetes costs through resource right-sizing, unused resource detection, and cluster efficiency analysis. Use for cost optimization, resource analysis, and capacity planning.
Teams using k8s-cost should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/k8s-cost/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How k8s-cost Compares
| Feature / Agent | k8s-cost | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Optimize Kubernetes costs through resource right-sizing, unused resource detection, and cluster efficiency analysis. Use for cost optimization, resource analysis, and capacity planning.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Kubernetes Cost Optimization Cost analysis and optimization using kubectl-mcp-server's cost tools. ## When to Apply Use this skill when: - User mentions: "cost", "savings", "optimize", "expensive", "budget" - Operations: cost analysis, right-sizing, cleanup unused resources - Keywords: "how much", "reduce", "efficiency", "waste", "overprovisioned" ## Priority Rules | Priority | Rule | Impact | Tools | |----------|------|--------|-------| | 1 | Find and delete unused PVCs | CRITICAL | `find_orphaned_pvcs` | | 2 | Right-size overprovisioned pods | HIGH | `get_resource_recommendations` | | 3 | Identify idle LoadBalancers | HIGH | `get_services` | | 4 | Scale down non-prod off-hours | MEDIUM | `scale_deployment` | | 5 | Consolidate small namespaces | LOW | Analysis | ## Quick Reference | Task | Tool | Example | |------|------|---------| | Namespace cost | `get_namespace_cost` | `get_namespace_cost(namespace)` | | Cluster cost | `get_cluster_cost` | `get_cluster_cost()` | | Unused PVCs | `find_orphaned_pvcs` | `find_orphaned_pvcs(namespace)` | | Right-sizing | `get_resource_recommendations` | `get_resource_recommendations(namespace)` | ## Quick Cost Analysis ### Get Cost Summary ```python get_namespace_cost(namespace) get_cluster_cost() ``` ### Find Unused Resources ```python find_unused_resources(namespace) find_orphaned_pvcs(namespace) ``` ### Resource Right-Sizing ```python get_resource_recommendations(namespace) get_pod_metrics(name, namespace) ``` ## Cost Optimization Workflow ### 1. Identify Overprovisioned Resources ```python get_resource_recommendations(namespace="production") get_pod_metrics(name, namespace) get_resource_usage(namespace) ``` ### 2. Find Idle Resources ```python find_orphaned_pvcs(namespace) find_unused_resources(namespace) ``` ### 3. Analyze Node Utilization ```python get_nodes() get_node_metrics() ``` ## Right-Sizing Guidelines | Current State | Recommendation | |--------------|----------------| | CPU usage < 10% of request | Reduce request by 50% | | CPU usage > 80% of request | Increase request by 25% | | Memory < 50% of request | Reduce request | | Memory near limit | Increase limit, monitor OOM | ## Cost by Resource Type ### Compute (Pods/Deployments) ```python get_resource_usage(namespace) get_pod_metrics(name, namespace) ``` ### Storage (PVCs) ```python get_pvc(namespace) find_orphaned_pvcs(namespace) ``` ### Network (LoadBalancers) ```python get_services(namespace) ``` ## Multi-Cluster Cost Analysis Compare costs across clusters: ```python get_cluster_cost(context="production") get_cluster_cost(context="staging") get_cluster_cost(context="development") ``` ## Cost Reduction Actions ### Immediate Wins 1. **Delete unused PVCs**: `find_orphaned_pvcs()` then delete 2. **Right-size pods**: Apply `get_resource_recommendations()` 3. **Scale down dev/staging**: Off-hours scaling ### Medium-term Optimizations 1. **Use Spot/Preemptible nodes**: For fault-tolerant workloads 2. **Implement HPA**: Auto-scale based on demand 3. **Use KEDA**: Scale to zero for event-driven workloads ### Long-term Strategy 1. **Reserved instances**: For stable production workloads 2. **Multi-tenant clusters**: Consolidate small clusters 3. **Right-size node pools**: Match workload requirements ## Automated Analysis Script For comprehensive cost analysis, see [scripts/find-overprovisioned.py](scripts/find-overprovisioned.py). ## KEDA for Cost Savings Scale to zero with KEDA: ```python keda_scaledobjects_list_tool(namespace) keda_scaledobject_get_tool(name, namespace) ``` KEDA reduces costs by: - Scaling pods to 0 when idle - Event-driven scaling (queue depth, etc.) - Cron-based scaling for predictable patterns ## Related Skills - [k8s-autoscaling](../k8s-autoscaling/SKILL.md) - HPA, VPA, KEDA - [k8s-troubleshoot](../k8s-troubleshoot/SKILL.md) - Resource debugging
Related Skills
k8s-vind
Manage vCluster (virtual Kubernetes clusters) instances using vind. Use when creating, managing, or operating lightweight virtual clusters for development, testing, or multi-tenancy.
k8s-troubleshoot
Debug Kubernetes pods, nodes, and workloads. Use when pods are failing, containers crash, nodes are unhealthy, or users mention debugging, troubleshooting, or diagnosing Kubernetes issues.
k8s-storage
Kubernetes storage management for PVCs, storage classes, and persistent volumes. Use when provisioning storage, managing volumes, or troubleshooting storage issues.
k8s-service-mesh
Manage Istio service mesh for traffic management, security, and observability. Use for traffic shifting, canary releases, mTLS, and service mesh troubleshooting.
k8s-security
Audit Kubernetes RBAC, enforce policies, and manage secrets. Use for security reviews, permission audits, policy enforcement with Kyverno/Gatekeeper, and secret management.
k8s-rollouts
Progressive delivery with Argo Rollouts and Flagger. Use when implementing canary deployments, blue-green deployments, or traffic shifting strategies.
k8s-policy
Kubernetes policy management with Kyverno and Gatekeeper. Use when enforcing security policies, validating resources, or auditing policy compliance.
k8s-operations
kubectl operations for applying, patching, deleting, and executing commands on Kubernetes resources. Use when modifying resources, running commands in pods, or managing resource lifecycle.
k8s-networking
Kubernetes networking management for services, ingresses, endpoints, and network policies. Use when configuring connectivity, load balancing, or network isolation.
k8s-multicluster
Manage multiple Kubernetes clusters, switch contexts, and perform cross-cluster operations. Use when working with multiple clusters, comparing environments, or managing cluster lifecycle.
k8s-kubevirt
Virtual machine management with KubeVirt on Kubernetes. Use when creating, managing, or troubleshooting VMs running on Kubernetes clusters.
k8s-kind
Manage kind (Kubernetes IN Docker) local clusters. Use when creating, testing, or developing with local Kubernetes clusters in Docker containers.