/gke-cost-optimization
Optimizes GKE costs, rightsizes workloads, and configures Spot VMs, CUDs, cost allocation, and resource quotas. Use when optimizing GKE cluster or workload costs, configuring GKE cost allocation or quotas, rightsizing CPU/memory requests, or selecting Spot VMs and machine types.
$ npx -y skills add google/skills --skill gke-cost-optimization --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/gke-cost-optimization
Context preview
The summary Claude sees to decide when to auto-load this skill.
Optimizes GKE costs, rightsizes workloads, and configures Spot VMs, CUDs, cost allocation, and resource quotas. Use when optimizing GKE cluster or workload costs, configuring GKE cost allocation or quotas, rightsizing CPU/memory requests, or selecting Spot VMs and machine types.
SKILL.md
gke-cost-optimization.SKILL.mdname: gke-cost-optimization
description: >-
Optimizes GKE costs, rightsizes workloads, and configures Spot VMs, CUDs, cost
allocation, and resource quotas. Use when optimizing GKE cluster or workload
costs, configuring GKE cost allocation or quotas, rightsizing CPU/memory
requests, or selecting Spot VMs and machine types. Don't use for general
compute class provisioning or GPU Selection (use gke-compute-classes instead).
metadata:
category: CloudObservabilityAndMonitoring
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:
| Setting | Value | Impact | | ------------------------ | ---------------------- | ----------------------- | | `autoscalingProfile` | `OPTIMIZE_UTILIZATION` | Aggressive node | : : : scale-down reduces idle : : : : compute : | `verticalPodAutoscaling` | `enabled` | VPA recommendations | : : : prevent : : : : over-provisioning : | Autopilot pricing | Pay per pod request | No charge for unused | : : : node capacity : | Node Auto Provisioning | enabled | Right-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
EOF3. 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:**
Condition | Action | Savings ----------------------------- | ---------------------------------- | ------- CPU request >5x P95 actual | Reduce to `P95 * 1.2` | High Memory request >3x P95 actual | Reduce to `P95 * 1.2` | High CPU request >2x P95 actual | Reduce to `P95 * 1.2` | Medium No resource requests set | Add 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: false4.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:**
Workload | Spot-Suitable? --------------------------------- | --------------- Batch / data processing | Yes Dev / test environments | Yes Stateless web/API (replicas >= 2) | Yes (with PDBs) Jobs with checkpointing | Yes Stateful workloads (databases) | No Single-replica critical services | No
5. Machine Type Selection
When choosing node shapes or configuring ComputeClasses:
| Family | Use Case | Relative Cost |
Read more
name: gke-cost-optimization description: >- Optimizes GKE costs, rightsizes workloads, and configures Spot VMs, CUDs, cost allocation, and resource quotas. Use when optimizing GKE cluster or workload costs, configuring GKE cost allocation or quotas, rightsizing CPU/memory requests, or selecting Spot VMs and machine types. Don't use for general compute class provisioning or GPU Selection (use gke-compute-classes instead). metadata: category: CloudObservabilityAndMonitoring
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:
| Setting | Value | Impact | | ------------------------ | ---------------------- | ----------------------- | | `autoscalingProfile` | `OPTIMIZE_UTILIZATION` | Aggressive node | : : : scale-down reduces idle : : : : compute : | `verticalPodAutoscaling` | `enabled` | VPA recommendations | : : : prevent : : : : over-provisioning : | Autopilot pricing | Pay per pod request | No charge for unused | : : : node capacity : | Node Auto Provisioning | enabled | Right-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
EOF3. 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:**
Condition | Action | Savings ----------------------------- | ---------------------------------- | ------- CPU request >5x P95 actual | Reduce to `P95 * 1.2` | High Memory request >3x P95 actual | Reduce to `P95 * 1.2` | High CPU request >2x P95 actual | Reduce to `P95 * 1.2` | Medium No resource requests set | Add 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: false4.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:**
Workload | Spot-Suitable? --------------------------------- | --------------- Batch / data processing | Yes Dev / test environments | Yes Stateless web/API (replicas >= 2) | Yes (with PDBs) Jobs with checkpointing | Yes Stateful workloads (databases) | No Single-replica critical services | No
5. Machine Type Selection
When choosing node shapes or configuring ComputeClasses:
| Family | Use Case | Relative Cost |
This repository contains Agent Skills for Google products and technologies, including Google Cloud. This repository is under active development.
Repo: google/skills
Other skills on google-skills.
- /data-manager-api-audience-ingestion
Guides developers through managing (adding, removing, and clearing) audience members for Google products using the Data Manager API and its associated client libraries. Use this skill when the user wants to upload audience members, remove specific users, or clear/replace an
Open skill - /data-manager-api-event-ingestion
Guides developers through implementing event and conversion ingestion to Google products using the Data Manager API /v1/events/ingest endpoint and its associated client libraries. Use this skill when the user wants to upload offline conversions, enhanced conversions for leads,
Open skill - /data-manager-api-setup
Guides developers through client library installation and authentication setup steps for the Data Manager API. Use this skill when a user is getting started with the Data Manager API and needs to setup their local environment, install the client library, or setup access to the
Open skill - /google-ads-api-account-diagnostics
Diagnoses Google Ads account performance issues such as conversion loss (value or volume), low lead flow/volume, and lost impression share (opportunities) due to ad rank, bids, or budgets. Use when troubleshooting sudden performance drops, analyzing campaign impression share
Open skill - /google-ads-api-mcp-setup
Guides developers through downloading, configuring, and installing the official open-source Google Ads MCP Server. Use this skill when a user wants to connect their AI assistant (such as Gemini, Claude Code, or Cursor) to their Google Ads account to query campaigns or retrieve
Open skill - /google-ads-api-quickstart
Guides developers through Google Ads API quickstart: credential setup, choosing from 6 client libraries/REST, configuring environments, and running a "retrieve campaigns" script. Troubleshoots common setup errors: USER_PERMISSION_DENIED, login_customer_id issues, and
Open skill

