New to Claude Skills? Learn how to install them →

Ggoogle on GitHub

GKE Cost Optimization

Free

Reduce your Google Kubernetes Engine costs effectively.

by google17.6k stars on google/skills
2 views
Updated Aug 10, 2026
Get this skill

Free · Opens the source repo

What GKE Cost Optimization does

GKE Cost Optimization is a skill designed to help developers and DevOps engineers minimize costs associated with Google Kubernetes Engine (GKE) while maintaining performance and reliability. This skill provides a comprehensive set of strategies and workflows aimed at optimizing resource usage, configuring cost allocation, and rightsizing workloads. By leveraging built-in features such as vertical pod autoscaling and node auto provisioning, users can achieve significant cost reductions without sacrificing service quality.

The skill guides users through essential workflows, starting with enabling cost allocation for better billing tracking across namespaces. This foundational step allows users to monitor resource utilization and identify wasteful spending. Once monitoring is in place, users can apply resource quotas to prevent excessive resource consumption in multi-tenant clusters, ensuring that costs are kept in check. The skill also emphasizes the importance of rightsizing CPU and memory requests, which is a common source of waste in Kubernetes environments.

Additionally, the skill introduces the use of Spot VMs for fault-tolerant workloads, which can lead to substantial cost savings. Users are provided with clear instructions on how to configure ComputeClasses and utilize node selectors to effectively implement Spot VMs. However, it is crucial to note the preemption risk associated with Spot VMs, making them suitable primarily for stateless workloads or batch processing tasks. Overall, GKE Cost Optimization is an essential tool for anyone looking to manage their GKE costs effectively while ensuring optimal resource utilization.

When to use it

Use this skill when you need to optimize costs for your GKE clusters, configure cost allocation, or rightsize your workloads to match actual resource usage.

When not to use it

This skill is not suitable for general compute class provisioning or GPU selection; for those needs, consider using the gke-compute-classes skill instead.

What you can build with it

Cost Allocation Setup

Enable cost allocation in GKE to track expenses across namespaces, allowing for better financial oversight.

Rightsizing Workloads

Implement vertical pod autoscaling to adjust resource requests based on actual usage, minimizing waste.

Utilizing Spot VMs

Configure Spot VMs for non-critical workloads to achieve significant cost savings while maintaining performance.

How to install GKE Cost Optimization

View source

1. Install with the skills CLI

npx skills add google/skills/gke-cost-optimization --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by google

GKE Cost Optimization

This reference covers strategies and workflows for reducing Google Kubernetes Engine (GKE) costs while maintaining a secure and reliable posture.

MCP Tools: get_k8s_resource, describe_k8s_resource, apply_k8s_manifest, patch_k8s_resource, get_cluster

Golden Path Cost Features

The golden path already includes cost-optimizing settings:

SettingValueImpact
autoscalingProfileOPTIMIZE_UTILIZATIONAggressive node
: : : scale-down reduces idle :
: : : compute :
verticalPodAutoscalingenabledVPA recommendations
: : : prevent :
: : : over-provisioning :
Autopilot pricingPay per pod requestNo charge for unused
: : : node capacity :
Node Auto ProvisioningenabledRight-sized node pools
: : : created automatically :

Workflows & Optimization Strategies

1. Prerequisite: Cost Allocation & Monitoring

To enable GKE cost allocation (--enable-cost-allocation) for billing tracking across namespaces and labels, inspect live cluster utilization (kubectl top), or run historical cost breakdown queries in BigQuery (bq), use the gke-cost-analysis skill. Once tracking is active and waste is diagnosed, apply the optimization workflows below.

2. Configure Resource Quotas

Resource quotas restrict total resource consumption across tenants in multi-tenant clusters, preventing runaway costs.

kubectl apply -f - <<EOF
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
  namespace: {namespace}
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 16Gi
    limits.cpu: "8"
    limits.memory: 32Gi
EOF

3. Pod Rightsizing (VPA & MPA)

Adjust pod resource requests to match actual utilization. Over-provisioned requests are one of the largest sources of waste.

  • Use VPA in Recommendation Mode:
# 1. Deploy VPA in recommendation mode
kubectl apply -f - <<EOF
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: {deployment_name}-vpa
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {deployment_name}
  updatePolicy:
    updateMode: "Off"
EOF

# 2. Wait 24+ hours for data collection

# 3. Read recommendations
kubectl get vpa {deployment_name}-vpa -o jsonpath='{.status.recommendation}'
  • Optimization Rules:
ConditionActionSavings
CPU request >5x P95 actualReduce to P95 * 1.2High
Memory request >3x P95 actualReduce to P95 * 1.2High
CPU request >2x P95 actualReduce to P95 * 1.2Medium
No resource requests setAdd requests (enables bin-packing)Medium
  • Use MPA: Reconcile HPA and VPA recommendations when scaling both horizontally and vertically to avoid conflicting scale events.
  • Review Cost Recommendations: Check Google Cloud Console (Cost Management > GKE Cost Optimization) for built-in rightsizing suggestions.

4. Spot VMs via ComputeClasses & NodeSelector

Use Spot VMs for fault-tolerant workloads to achieve 60-90% cost reduction.

4.1 ComputeClass Configuration

apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
  name: spot-with-fallback
spec:
  activeMigration:
    optimizeRulePriority: true
  priorities:
  - machineFamily: n4
    spot: true
  - machineFamily: n4
    spot: false

4.2 Direct Workload Spot Selection (nodeSelector)

For stateless or batch workloads in GKE Autopilot, target Spot capacity directly using nodeSelector:

[!WARNING] Preemption Warning: Spot VMs are interruptible and can be preempted at any time with a 30-second notice. Workloads must be fault-tolerant and run with at least 2 replicas for high availability. Always explicitly warn users about this preemption risk when recommending Spot VMs.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: stateless-spot-app
spec:
  replicas: 2
  template:
    spec:
      nodeSelector:
        cloud.google.com/gke-provisioning: Spot
      terminationGracePeriodSeconds: 25  # Must be < 30s for Spot preemption handling
      containers:
      - name: app
        image: {image_name}
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "sleep 5"]

Spot-Suitable Workloads:

WorkloadSpot-Suitable?
Batch / data processingYes
Dev / test environmentsYes
Stateless web/API (replicas >= 2)Yes (with PDBs)
Jobs with checkpointingYes
Stateful workloads (databases)No
Single-replica critical servicesNo

5. Machine Type Selection

When choosing node shapes or configuring ComputeClasses:

FamilyUse CaseRelative Cost
e2General purpose, burstableLowest
t2a / t2dScale-out (Arm/AMD), price-performanceLow
: : optimized : :
n4aAxion Arm-based, general-purposeLow
: : price-performance : :
n4 / n4dGeneral purpose (Intel/AMD), flexible shapesLow-Medium
c4aCompute-optimized (Arm), high efficiencyMedium-High
c3 / c4Compute-optimized (Intel)Medium-High
c3d / c4dCompute-optimized (AMD), high throughputMedium-High
ek-standardAutopilot enhanced (golden path)Medium
m3 / x4Memory-optimized, SAP HANA, large databasesHigh
g2 (L4 GPU)AI inferenceHigh
a3 (H100 GPU)AI trainingHighest
a4 / a4xUltra-scale AI (Blackwell GPUs)Highest

6. Committed Use Discounts (CUDs)

For steady-state workloads with predictable baseline usage, purchase 1-year or 3-year CUDs:

  • 1-year: ~20-30% discount
  • 3-year: ~50-55% discount
  • Applied automatically to matching usage across the region.
  • Purchase via Google Cloud Console > Billing > Committed use discounts.

7. Cluster Management & Multi-Tenancy

  • Stop/start dev clusters: Idle dev clusters cost money even with no workloads due to control plane fees.
  • Right-size node pools (Standard): Use Cluster Autoscaler with appropriate min/max limits.
  • Multi-tenant consolidation: Share a single cluster across multiple engineering teams instead of maintaining per-team clusters, using Namespaces and ResourceQuotas to isolate workloads.

Cost & Utilization Monitoring

To inspect live node/pod utilization (kubectl top nodes/pods), view cluster cost budgets (gcloud billing budgets list), or query detailed billing reports in BigQuery (bq query), refer to the gke-cost-analysis skill.

Dev/Test Cost Savings

For non-production environments, the following golden path deviations provide cost efficiency without impacting production safety:

| Setting | Production (Golden | Dev/Test | : : Path) : : | ----------------------- | ------------------ | ----------------------------- | | Cluster mode | Autopilot | Autopilot (cheaper with fewer | : : : pods) : | Release channel | Regular | Rapid (get fixes faster) | | Private nodes | Required | Optional (simpler access) | | Monitoring components | Full suite | SYSTEM_COMPONENTS only | | Secret Manager rotation | 120s | Disabled | | Maintenance windows | Configured | Not needed |

Best Practices Summary

  1. Enable Cost Allocation: Always enable GKE cost allocation (--enable-cost-allocation) to gain billing transparency across namespaces and labels.
  2. Enforce Resource Quotas: Restrict namespace CPU/memory limits in multi-tenant environments to prevent runaway costs or noisy neighbors.
  3. Rightsize Continuously: Run VPA in recommendation mode (updateMode: Off) and adjust requests to match P95 * 1.2.
  4. Leverage Spot VMs: Use Spot VMs with nodeSelector or ComputeClass for stateless, fault-tolerant workloads to save 60-90%.
  5. Optimize Autoscaling Profile: Use OPTIMIZE_UTILIZATION for aggressive node scale-down on idle compute.
  6. Consolidate & Clean Up: Stop idle development clusters and consolidate multi-team workloads into shared multi-tenant clusters.

Frequently asked questions about GKE Cost Optimization

Similar skills