Generated banner for Gke Cost Analysis
Generated logo for Gke Cost Analysis

Gke Cost Analysis

GoogleOfficialPublished by Google

  • Skill
  • Research and analysis
  • Cloud and DevOps
  • Apache-2.0
  • No issues found

From the author

Answer natural language questions and perform analysis on GKE cluster and workload costs using BigQuery billing exports, cost allocation data, and live cluster monitoring metrics. Use when querying GKE costs across projects, namespaces, or workloads, analyzing billing reports in BigQuery (`bq`), checking cluster cost budgets (`gcloud billing`), or diagnosing cost drivers like pod requests vs. actual utilization (`kubectl top`). Don't use for applying cost optimization changes, creating rightsizing manifests (VPA/MPA), or selecting ComputeClasses (use gke-cost-optimization instead).
— the description by Google

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The gke-cost-analysis skill provides an expert framework for investigating Google Kubernetes Engine (GKE) expenditures. It leverages GCP Billing Detailed BigQuery exports to provide historical cost breakdowns and uses live cluster monitoring tools like kubectl top to diagnose current resource utilization. The skill guides users through identifying cost drivers, verifying cost allocation settings, and interpreting the impact of Autopilot versus Standard pricing models.

What it does

  • Queries historical GKE costs using BigQuery billing exports.
  • Analyzes cost drivers by comparing pod resource requests against actual utilization.
  • Provides SQL templates for workload, namespace, and cluster-level cost breakdowns.
  • Inspects live cluster resource consumption using kubectl top.
  • Checks billing budgets via the gcloud CLI.
  • Advises on enabling GKE cost allocation for granular billing data.

When to use it

  • When you need to identify the most expensive namespaces or workloads in your GKE environment.
  • When investigating unexpected spikes in cluster billing.
  • When comparing actual pod resource usage against provisioned requests to identify waste.
  • When you need to generate reports on GKE costs across multiple projects or clusters.

Advantages

  • Provides actionable insights by correlating billing data with live cluster metrics.
  • Offers standardized BigQuery SQL templates for consistent cost reporting.
  • Helps distinguish between Autopilot and Standard mode cost drivers.
  • Includes clear guidance on enabling necessary cost allocation labels.

Usage examples

“What are my most expensive namespaces in the production cluster over the last month?”
The agent provides a BigQuery SQL query to aggregate costs by namespace, filtered by the cluster name and the last 30 days.
“Why is my GKE Autopilot cluster cost higher than expected?”
The agent explains how Autopilot billing is driven by pod resource requests and provides commands to compare these requests against actual pod utilization.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/google/gke-cost-analysis/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip gke-cost-analysis.zip -d .agents/skills

Documentation by Google

GKE Cost Analysis

This skill provides guidance on answering natural language questions about GKE-related costs, billing reports, and utilization analysis.

Attribution

MUST READ: Before executing any gcloud, REST API, or MCP command, you MUST read Usage Attribution. For commands executed directly in the terminal (never in generated scripts, Terraform, or user code), prefix gcloud with CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-cost-analysis)" and append agent-skills/1.0 (skill:gke-cost-analysis) to User-Agent headers.

Overview

When users ask about GKE costs (e.g., "What are my costs across projects?", "What's my most expensive namespace?", "Why is my cluster cost spiking?"), use this skill to provide a structured and expert response using BigQuery billing exports, cost allocation metadata, and live cluster metrics.

Instructions

When handling a cost-related question:

  1. Provide a Direct Answer: Address the specific cost question or analytical request clearly and concisely.

  2. Explain BigQuery Integration: Explain how to query BigQuery for historical cost breakdown. Note that GKE costs originate from the GCP Billing Detailed BigQuery Export (gcp_billing_export_resource_v1_*).

  3. Check & Verify Cost Allocation: Explain that GKE Cost Allocation must be enabled on the cluster (--enable-cost-allocation) for namespace, label, and workload-level billing granularity. If queries return empty labels, provide the gcloud command to enable it.

  4. Analyze Pricing Drivers & Utilization: When diagnosing cost drivers, explain whether the cluster is in Autopilot (billed by requested pod CPU/memory) or Standard mode (billed by underlying VM node size + control plane fees), and compare live utilization (kubectl top) against provisioned requests.

  5. Provide Actionable Commands/Queries: Provide concrete BigQuery CLI (bq query) commands or read-only gcloud/kubectl inspection commands. Prefer bq over BigQuery Studio when available.

Key Points & Pricing Drivers

  • Data Source: GKE costs come from GCP Billing Detailed BigQuery Export. The user must provide the full path to their BigQuery table (dataset name and table name containing the Billing Account ID).

  • Granularity Requirement: GKE Cost Allocation (--enable-cost-allocation) must be enabled on the cluster to populate goog-k8s-cluster-name, k8s-namespace, k8s-workload-name, and k8s-workload-type labels in BigQuery.

  • Autopilot vs. Standard Cost Drivers:

    • Autopilot Pricing: Billed directly on pod resource requests (requests.cpu, requests.memory, ephemeral storage). Over-requested pods drive up billing regardless of whether the pod actively uses those CPU cycles or memory.

    • Standard Pricing: Billed on provisioned node pool VMs (e2, n4, c3, etc.). Idle nodes or multiple low-utilization dev clusters drive excess infrastructure costs.

    • Cluster Management Fee: ~$0.10/hour per cluster applies to BOTH Standard and Autopilot modes. The free tier waives it for one eligible cluster per billing account.

  • Credits & Discounts Impact: When analyzing cost versus cost_before_credits, note that Committed Use Discounts (CUDs) and Spot VMs appear as credits or reduced rate charges in the billing export.

  • Tools & Syntax: BigQuery CLI (bq) is preferred. When writing Standard SQL queries, use a dot (.) instead of a colon (:) to separate the project ID and dataset name ({project_id}.{dataset_name}.{table_name}).

  • Defaults: Assume last 30 days, row limit 10, ordering by cost descending (ORDER BY cost DESC), unless specified otherwise.

Live Cluster & Cost Monitoring

Use read-only CLI commands to inspect current cluster budgets, node utilization, and pod resource consumption vs. requests:

# View billing budgets for an account (requires Cost Management API)
gcloud billing budgets list --billing-account={billing_account} --quiet

# View live node resource utilization across the cluster
kubectl top nodes

# View pod resource usage across namespaces (compare against requested limits to diagnose waste)
kubectl top pods --all-namespaces --containers

Warning — cluster mutation, not read-only: Enabling GKE cost allocation modifies the cluster. Get explicit user confirmation before running it, and note that namespace/workload labels populate in the billing export only from enablement onward (no historical backfill).

gcloud container clusters update {cluster_name} \
    --enable-cost-allocation \
    --region {region}

Applying Cost Optimizations

To apply rightsizing changes based on analysis (such as setting up VPA recommendation mode, adjusting CPU/memory to P95 * 1.2, configuring Spot VMs via nodeSelector or ComputeClass, enforcing ResourceQuotas, or selecting machine types and CUDs), use the gke-cost-optimization skill.

BigQuery Query Templates

Ready-to-adapt bq query templates — single workload cost, per-workload per-cluster breakdown, per-namespace breakdown — with the placeholder policy and defaults (30 days, LIMIT 10, ORDER BY cost DESC) are in references/billing-queries.md. All parameters (dataset, table, project, cluster, etc.) must be replaced with user values.

Note: Checking that the goog-k8s-cluster-name label exists scopes the total billing data specifically to GKE costs.

Files

ATTRIBUTION.md

Attribution

This folder is an unmodified copy of the Agent Skill "gke-cost-analysis", distributed by AutoGineer (https://autogineer.com/agent-skills).

The skill's own files are unmodified copies. AutoGineer is not affiliated with or endorsed by the author or the publisher.

Files added by AutoGineer

  • ATTRIBUTION.md: this file, written by AutoGineer

  • LICENSE: copied from LICENSE

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs a command-line tool, Needs Node.js

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Google
Publisher
Google (Official)
Source
google/skills · skills/cloud/gke-cost-analysis · commit 2194d3b
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Google.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download gke-cost-analysis.zip