Agent Skillsgoogle/skills › gke-cost-analysis

gke-cost-analysis

GitHub

用于分析GKE集群及工作负载成本,通过BigQuery账单导出、成本分配数据和实时指标回答自然语言问题。支持跨项目/命名空间查询、预算检查及利用率诊断,但不涉及优化实施。

skills/cloud/gke-cost-analysis/SKILL.md google/skills

触发场景

询问GKE集群或工作负载的具体费用 分析成本飙升原因或利用率驱动因素 查询跨项目或命名空间的账单报告

安装

npx skills add google/skills --skill gke-cost-analysis -g -y
更多选项

非标准路径

npx skills add https://github.com/google/skills/tree/main/skills/cloud/gke-cost-analysis -g -y

不安装直接使用

npx skills use google/skills@gke-cost-analysis

指定 Agent (Claude Code)

npx skills add google/skills --skill gke-cost-analysis -a claude-code -g -y

安装 repo 全部 skill

npx skills add google/skills --all -g -y

预览 repo 内 skill

npx skills add google/skills --list

SKILL.md

Frontmatter
{
    "name": "gke-cost-analysis",
    "metadata": {
        "category": "CloudObservabilityAndMonitoring"
    },
    "description": "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)."
}

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:

  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.) plus a cluster management fee ($0.10/hour). Idle nodes or multiple low-utilization dev clusters drive excess infrastructure costs.
  • 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

# Verify/Enable GKE cost allocation on a cluster for namespace-level billing tracking
gcloud container clusters update {cluster_name} \
    --enable-cost-allocation \
    --region {region}

# 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

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.

Example BigQuery Queries

Use these queries as templates to answer questions. All parameters (dataset, table, project, cluster, etc.) must be replaced with user values.

Cost of a Single Workload in a Single Cluster

bq query --nouse_legacy_sql '
SELECT
  SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS cost,
  SUM(cost) AS cost_before_credits
FROM {billing_export_table} AS bqe
WHERE _PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND project.id = "{project_id}"
  AND EXISTS(SELECT * FROM bqe.labels AS l WHERE l.key = "goog-k8s-cluster-location" AND l.value = "{region}")
  AND EXISTS(SELECT * FROM bqe.labels AS l WHERE l.key = "goog-k8s-cluster-name" AND l.value = "{cluster_name}")
  AND EXISTS(SELECT * FROM bqe.labels AS l WHERE l.key = "k8s-namespace" AND l.value = "{namespace}")
  AND EXISTS(SELECT * FROM bqe.labels AS l WHERE l.key = "k8s-workload-type" AND l.value = "{workload_type}")
  AND EXISTS(SELECT * FROM bqe.labels AS l WHERE l.key = "k8s-workload-name" AND l.value = "{workload_name}")
;
'

Cost of Each Workload in Each Cluster

bq query --nouse_legacy_sql '
SELECT
  project.id AS project_id,
  (SELECT l.value FROM bqe.labels AS l WHERE l.key = "goog-k8s-cluster-location" LIMIT 1) AS cluster_location,
  (SELECT l.value FROM bqe.labels AS l WHERE l.key = "goog-k8s-cluster-name" LIMIT 1) AS cluster_name,
  (SELECT l.value FROM bqe.labels AS l WHERE l.key = "k8s-namespace" LIMIT 1) AS k8s_namespace,
  (SELECT l.value FROM bqe.labels AS l WHERE l.key = "k8s-workload-type" LIMIT 1) AS k8s_workload_type,
  (SELECT l.value FROM bqe.labels AS l WHERE l.key = "k8s-workload-name" LIMIT 1) AS k8s_workload_name,
  SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS cost,
  SUM(cost) AS cost_before_credits
FROM {billing_export_table} AS bqe
WHERE _PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND EXISTS(SELECT * FROM bqe.labels AS l WHERE l.key = "goog-k8s-cluster-name")
GROUP BY 1, 2, 3, 4, 5, 6
ORDER BY 7 DESC
LIMIT 10
;
'

Cost Breakdown by Namespace in a Cluster

bq query --nouse_legacy_sql '
SELECT
  (SELECT l.value FROM bqe.labels AS l WHERE l.key = "k8s-namespace" LIMIT 1) AS k8s_namespace,
  SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS net_cost,
  SUM(cost) AS gross_cost
FROM {billing_export_table} AS bqe
WHERE _PARTITIONTIME >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND project.id = "{project_id}"
  AND EXISTS(SELECT * FROM bqe.labels AS l WHERE l.key = "goog-k8s-cluster-name" AND l.value = "{cluster_name}")
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10
;
'

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

版本历史

  • 05679aa 当前 2026-07-31 07:59

同 Skill 集合

skills/ads/data-manager-api-audience-ingestion/SKILL.md
skills/ads/data-manager-api-event-ingestion/SKILL.md
skills/ads/data-manager-api-setup/SKILL.md
skills/ads/data-manager-api/data-manager-api-audience-ingestion/SKILL.md
skills/ads/data-manager-api/data-manager-api-event-ingestion/SKILL.md
skills/ads/data-manager-api/data-manager-api-setup/SKILL.md
skills/ads/google-ads-api-mcp-setup/SKILL.md
skills/ads/google-ads-api/google-ads-api-mcp-setup/SKILL.md
skills/ads/google-mobile-ads-android-migrate-to-next-gen/SKILL.md
skills/ads/google-mobile-ads-banner/SKILL.md
skills/ads/google-mobile-ads-get-started/SKILL.md
skills/ads/google-mobile-ads-interstitial/SKILL.md
skills/ads/google-mobile-ads-rewarded/SKILL.md
skills/ads/google-mobile-ads/google-mobile-ads-android-migrate-to-next-gen/SKILL.md
skills/ads/google-mobile-ads/google-mobile-ads-banner/SKILL.md
skills/ads/google-mobile-ads/google-mobile-ads-get-started/SKILL.md
skills/ads/google-mobile-ads/google-mobile-ads-interstitial/SKILL.md
skills/ads/google-mobile-ads/google-mobile-ads-rewarded/SKILL.md
skills/ads/ima-sdk-basics/SKILL.md
skills/ads/interactive-media-ads/ima-sdk-basics/SKILL.md
skills/analytics/google-analytics-admin-api-basics/SKILL.md
skills/cloud/agent-platform-alert-configuration/SKILL.md
skills/cloud/agent-platform-endpoint-management/SKILL.md
skills/cloud/agent-platform-migrate-from-ai-studio/SKILL.md
skills/cloud/agent-platform-model-registry/SKILL.md
skills/cloud/agent-platform-prompt-management/SKILL.md
skills/cloud/agent-platform-rag-engine-management/SKILL.md
skills/cloud/agent-platform-skill-registry/SKILL.md
skills/cloud/agent-platform-troubleshooting/SKILL.md
skills/cloud/agent-platform-tuning-management/SKILL.md
skills/cloud/agent-platform-tuning/SKILL.md
skills/cloud/alloydb-basics/SKILL.md
skills/cloud/bigquery-basics/SKILL.md
skills/cloud/bigquery-bigframes/SKILL.md
skills/cloud/bigtable-basics/SKILL.md
skills/cloud/cloud-logging-configuration-basics/SKILL.md
skills/cloud/cloud-logging-cross-project-configuration/SKILL.md
skills/cloud/cloud-logging-query-generation/SKILL.md
skills/cloud/cloud-monitoring-metric-selection/SKILL.md
skills/cloud/cloud-run-basics/SKILL.md
skills/cloud/datalineage-summary/SKILL.md
skills/cloud/detection-engineering-coverage-evaluation/SKILL.md
skills/cloud/developer-device-platform-basics/SKILL.md
skills/cloud/firebase-basics/SKILL.md
skills/cloud/gcloud/SKILL.md
skills/cloud/gemini-agents-api/SKILL.md
skills/cloud/gemini-api/SKILL.md
skills/cloud/gemini-interactions-api/SKILL.md
skills/cloud/gke-ai-troubleshooting-jobset-interruption/SKILL.md
skills/cloud/gke-app-onboarding/SKILL.md

元信息

文件数
0
版本
46a4414
Hash
0c7f585f
收录时间
2026-07-31 07:59

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-05 19:21
浙ICP备14020137号-1 $访客地图$