gke-cost-analysis
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).
摘要
- 用途
- 它结合 BigQuery 导出的帐单数据、成本分配中继数据与实时资源用量,协助解读 GKE 费用,并说明 Autopilot 与 Standard 计价方式的差异。
- 使用时机
- 当你想厘清费用或用量异常背后的计价与成本分配因素,而非实际运行资源调整或其他成本变更时,请使用它。
- 输出结果
- 它会提供精简的成本说明、可调整的 BigQuery 查找,以及唯读的 gcloud 或 kubectl 检查方式,并指出何时需要成本分配数据或计价模式的背景信息。
上游变更(4 条,最新收录 2026-09-21)
becc4b8 Enforce semantic versioning (MAJOR.MINOR.PATCH) for skills. 在 GKE 成本分析技能中添加设为 1.0.0 的语意化版本中继数据。 bf643de Upgrade gke-cost-analysis skill. 厘清集群管理费适用于两种 GKE 模式,将激活成本分配标示为会变更集群且不回补历史数据的操作,并链接至存放查找范本的参考文档。 8f5179b Add category metadata to skills and update README.md with new skills and external links. 为此技能添加 CloudObservabilityAndMonitoring 类别中继数据。 24de7eb Merged gke-cost into gke-cost-analysis skill and added 5-case evaluation suite. 添加 GKE 成本分析技能初始版本,提供帐单导出、成本分配、计价因素、使用率检查及 BigQuery 查找范例的指引。 npx skills add "lettucebo/Skills#v2.2.0@gke-cost-analysis" --full-depth ⚠ v2.2.0 发布后即可使用
GKE Cost Analysis
This skill provides guidance on answering natural language questions about GKE-related costs, billing reports, and utilization analysis.
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:
- Provide a Direct Answer: Address the specific cost question or analytical request clearly and concisely.
- 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_*). - 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 thegcloudcommand to enable it. - 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. - Provide Actionable Commands/Queries: Provide concrete BigQuery CLI (
bq query) commands or read-onlygcloud/kubectlinspection commands. Preferbqover 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 populategoog-k8s-cluster-name,k8s-namespace,k8s-workload-name, andk8s-workload-typelabels 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.
- Autopilot Pricing: Billed directly on pod resource requests
(
- Credits & Discounts Impact: When analyzing
costversuscost_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.