Answer natural language questions and perform analysis on GKE cluster and workload costs using BigQuery billing exports, cost allocation data, and live cluster
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-gke-cost-analysis-2dd694807dee ,按照其中的说明把「gke-cost-analysis」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
This skill provides guidance on answering natural language questions about GKE-related costs, billing reports, and utilization analysis.
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.
When handling a cost-related question:
gcp_billing_export_resource_v1_*).--enable-cost-allocation) for namespace, label,
and workload-level billing granularity. If queries return empty labels,
provide the gcloud command to enable it.kubectl top) against
provisioned requests.bq query) commands or read-only gcloud/kubectl inspection commands. Prefer
bq over BigQuery Studio when available.--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.requests.cpu, requests.memory, ephemeral storage). Over-requested
pods drive up billing regardless of whether the pod actively uses those
CPU cycles or memory.e2, n4,
c3, etc.). Idle nodes or multiple low-utilization dev clusters drive
excess infrastructure costs.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.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}).ORDER BY cost DESC), unless specified otherwise.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}
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.
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.