{"data":{"slug":"github-google-skills-skills-cloud-gke-cost-analysis-95a29f1e5761","title":"GKE Cost Analysis and Billing Breakdown","summary":"Analyze GKE cluster costs, billing reports, and utilization using BigQuery billing exports and live metrics from `kubectl top`. This skill provides actionable commands and insights for cost drivers, including namespace-level and workload-level breakdowns.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-cost-analysis-95a29f1e5761","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-gke-cost-analysis-95a29f1e5761","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-cost-analysis-95a29f1e5761.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-cost-analysis-95a29f1e5761\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud`, REST API, or MCP command, you must read [Usage Attribution](references\/attribution.md). For terminal commands, 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.","instructions":"---\nname: gke-cost-analysis\nmetadata:\n  version: \"1.0.1\"\n  category: CloudObservabilityAndMonitoring\ndescription: >-\n  Answer natural language questions and perform analysis on GKE cluster and\n  workload costs using BigQuery billing exports, cost allocation data, and live\n  cluster monitoring metrics. Use when querying GKE costs across projects,\n  namespaces, or workloads, analyzing billing reports in BigQuery (`bq`), checking\n  cluster cost budgets (`gcloud billing`), or diagnosing cost drivers like pod\n  requests vs. actual utilization (`kubectl top`). Don't use for applying cost\n  optimization changes, creating rightsizing manifests (VPA\/MPA), or selecting\n  ComputeClasses (use gke-cost-optimization instead).\n---\n\n# GKE Cost Analysis\n\nThis skill provides guidance on answering natural language questions about\nGKE-related costs, billing reports, and utilization analysis.\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-cost-analysis)\"`\nand append `agent-skills\/1.0 (skill:gke-cost-analysis)` to `User-Agent` headers.\n\n## Overview\n\nWhen users ask about GKE costs (e.g., \"What are my costs across projects?\",\n\"What's my most expensive namespace?\", \"Why is my cluster cost spiking?\"), use\nthis skill to provide a structured and expert response using BigQuery billing\nexports, cost allocation metadata, and live cluster metrics.\n\n## Instructions\n\nWhen handling a cost-related question:\n\n1.  **Provide a Direct Answer**: Address the specific cost question or\n    analytical request clearly and concisely.\n2.  **Explain BigQuery Integration**: Explain how to query BigQuery for\n    historical cost breakdown. Note that GKE costs originate from the GCP\n    Billing Detailed BigQuery Export (`gcp_billing_export_resource_v1_*`).\n3.  **Check & Verify Cost Allocation**: Explain that GKE Cost Allocation must be\n    enabled on the cluster (`--enable-cost-allocation`) for namespace, label,\n    and workload-level billing granularity. If queries return empty labels,\n    provide the `gcloud` command to enable it.\n4.  **Analyze Pricing Drivers & Utilization**: When diagnosing cost drivers,\n    explain whether the cluster is in Autopilot (billed by requested pod\n    CPU\/memory) or Standard mode (billed by underlying VM node size + control\n    plane fees), and compare live utilization (`kubectl top`) against\n    provisioned requests.\n5.  **Provide Actionable Commands\/Queries**: Provide concrete BigQuery CLI (`bq\n    query`) commands or read-only `gcloud`\/`kubectl` inspection commands. Prefer\n    `bq` over BigQuery Studio when available.\n\n## Key Points & Pricing Drivers\n\n-   **Data Source**: GKE costs come from GCP Billing Detailed BigQuery Export.\n    The user must provide the full path to their BigQuery table (dataset name\n    and table name containing the Billing Account ID).\n-   **Granularity Requirement**: GKE Cost Allocation\n    (`--enable-cost-allocation`) must be enabled on the cluster to populate\n    `goog-k8s-cluster-name`, `k8s-namespace`, `k8s-workload-name`, and\n    `k8s-workload-type` labels in BigQuery.\n-   **Autopilot vs. Standard Cost Drivers**:\n    -   **Autopilot Pricing**: Billed directly on pod resource requests\n        (`requests.cpu`, `requests.memory`, ephemeral storage). Over-requested\n        pods drive up billing regardless of whether the pod actively uses those\n        CPU cycles or memory.\n    -   **Standard Pricing**: Billed on provisioned node pool VMs (`e2`, `n4`,\n        `c3`, etc.). Idle nodes or multiple low-utilization dev clusters drive\n        excess infrastructure costs.\n    -   **Cluster Management Fee**: ~$0.10\/hour per cluster applies to BOTH\n        Standard and Autopilot modes. The free tier waives it for one eligible\n        cluster per billing account.\n-   **Credits & Discounts Impact**: When analyzing `cost` versus\n    `cost_before_credits`, note that Committed Use Discounts (CUDs) and Spot VMs\n    appear as credits or reduced rate charges in the billing export.\n-   **Tools & Syntax**: BigQuery CLI (`bq`) is preferred. When writing Standard\n    SQL queries, use a dot (`.`) instead of a colon (`:`) to separate the\n    project ID and dataset name (`{project_id}.{dataset_name}.{table_name}`).\n-   **Defaults**: Assume last 30 days, row limit 10, ordering by cost descending\n    (`ORDER BY cost DESC`), unless specified otherwise.\n\n## Live Cluster & Cost Monitoring\n\nUse read-only CLI commands to inspect current cluster budgets, node utilization,\nand pod resource consumption vs. requests:\n\n```bash\n# View billing budgets for an account (requires Cost Management API)\ngcloud billing budgets list --billing-account={billing_account} --quiet\n\n# View live node resource utilization across the cluster\nkubectl top nodes\n\n# View pod resource usage across namespaces (compare against requested limits to diagnose waste)\nkubectl top pods --all-namespaces --containers\n```\n\n> **Warning \u2014 cluster mutation, not read-only:** Enabling GKE cost allocation\n> modifies the cluster. Get explicit user confirmation before running it, and\n> note that namespace\/workload labels populate in the billing export only from\n> enablement onward (no historical backfill).\n>\n> ```bash\n> gcloud container clusters update {cluster_name} \\\n>     --enable-cost-allocation \\\n>     --region {region}\n> ```\n\n## Applying Cost Optimizations\n\nTo apply rightsizing changes based on analysis (such as setting up `VPA`\nrecommendation mode, adjusting CPU\/memory to `P95 * 1.2`, configuring Spot VMs\nvia `nodeSelector` or `ComputeClass`, enforcing `ResourceQuotas`, or selecting\nmachine types and CUDs), use the **`gke-cost-optimization`** skill.\n\n## BigQuery Query Templates\n\nReady-to-adapt `bq query` templates \u2014 single workload cost, per-workload\nper-cluster breakdown, per-namespace breakdown \u2014 with the placeholder policy\nand defaults (30 days, `LIMIT 10`, `ORDER BY cost DESC`) are in\n[references\/billing-queries.md](references\/billing-queries.md). All parameters\n(dataset, table, project, cluster, etc.) must be replaced with user values.\n\nNote: Checking that the `goog-k8s-cluster-name` label exists scopes the total\nbilling data specifically to GKE costs.\n","use_cases":["Identify the most expensive namespace in your GKE cluster.","Diagnose cost drivers like pod resource requests vs. actual utilization.","Analyze historical cost data from BigQuery billing exports."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/gke-cost-analysis\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T15:56:11.000000Z","updated_at":"2026-11-17T10:20:00.000000Z","seo_title":"GKE Cost Analysis and Billing Breakdown","seo_description":"Analyze GKE cluster costs, billing reports, and utilization with BigQuery and live metrics. Use this skill to answer natural language questions about GKE costs and cost-","seo_keywords":["GKE cost analysis","BigQuery billing export","GKE cost allocation","GKE cluster utilization","GKE cost breakdown"]}}