Agent skill
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.
Install this agent skill to your Project
npx add-skill https://github.com/rohitg00/kubectl-mcp-server/tree/main/kubernetes-skills/claude/k8s-cost
Metadata
Additional technical details for this skill
- tools
- 8
- author
- rohitg00
- version
- 1.0.0
- category
- observability
SKILL.md
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
get_namespace_cost(namespace)
get_cluster_cost()
Find Unused Resources
find_unused_resources(namespace)
find_orphaned_pvcs(namespace)
Resource Right-Sizing
get_resource_recommendations(namespace)
get_pod_metrics(name, namespace)
Cost Optimization Workflow
1. Identify Overprovisioned Resources
get_resource_recommendations(namespace="production")
get_pod_metrics(name, namespace)
get_resource_usage(namespace)
2. Find Idle Resources
find_orphaned_pvcs(namespace)
find_unused_resources(namespace)
3. Analyze Node Utilization
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)
get_resource_usage(namespace)
get_pod_metrics(name, namespace)
Storage (PVCs)
get_pvc(namespace)
find_orphaned_pvcs(namespace)
Network (LoadBalancers)
get_services(namespace)
Multi-Cluster Cost Analysis
Compare costs across clusters:
get_cluster_cost(context="production")
get_cluster_cost(context="staging")
get_cluster_cost(context="development")
Cost Reduction Actions
Immediate Wins
- Delete unused PVCs:
find_orphaned_pvcs()then delete - Right-size pods: Apply
get_resource_recommendations() - Scale down dev/staging: Off-hours scaling
Medium-term Optimizations
- Use Spot/Preemptible nodes: For fault-tolerant workloads
- Implement HPA: Auto-scale based on demand
- Use KEDA: Scale to zero for event-driven workloads
Long-term Strategy
- Reserved instances: For stable production workloads
- Multi-tenant clusters: Consolidate small clusters
- Right-size node pools: Match workload requirements
Automated Analysis Script
For comprehensive cost analysis, see scripts/find-overprovisioned.py.
KEDA for Cost Savings
Scale to zero with KEDA:
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 - HPA, VPA, KEDA
- k8s-troubleshoot - Resource debugging
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
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-incident
Respond to Kubernetes incidents with runbooks and diagnostics. Use for outages, pod failures, node issues, network problems, and emergency response.
k8s-gitops
Manage GitOps workflows with Flux and ArgoCD. Use for sync status, reconciliation, app management, source management, and GitOps troubleshooting.
k8s-autoscaling
Configure Kubernetes autoscaling with HPA, VPA, and KEDA. Use for horizontal/vertical pod autoscaling, event-driven scaling, and capacity management.
k8s-deploy
Deploy and manage Kubernetes workloads with progressive delivery. Use for deployments, rollouts, blue-green, canary releases, scaling, and release management.
k8s-rollouts
Progressive delivery with Argo Rollouts and Flagger. Use when implementing canary deployments, blue-green deployments, or traffic shifting strategies.
Didn't find tool you were looking for?