GKE Cost Analysis

GKE Cost Analysis

Helps an AI agent answer questions about GKE cluster and workload costs using BigQuery billing exports, cost allocation data and live kubectl metrics.

Skill files3 files

references/

SKILL.md133 lines
1
---
2
name: gke-cost-analysis
3
metadata:
4
version: "1.0.1"
5
category: CloudObservabilityAndMonitoring
6
description: >-
7
Answer natural language questions and perform analysis on GKE cluster and
8
workload costs using BigQuery billing exports, cost allocation data, and live
9
cluster monitoring metrics. Use when querying GKE costs across projects,
10
namespaces, or workloads, analyzing billing reports in BigQuery (`bq`), checking
11
cluster cost budgets (`gcloud billing`), or diagnosing cost drivers like pod
12
requests vs. actual utilization (`kubectl top`). Don't use for applying cost
13
optimization changes, creating rightsizing manifests (VPA/MPA), or selecting
14
ComputeClasses (use gke-cost-optimization instead).
15
---
16
17
# GKE Cost Analysis
18
19
This skill provides guidance on answering natural language questions about
20
GKE-related costs, billing reports, and utilization analysis.
21
22
## Attribution
23
24
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
25
MUST read [Usage Attribution](references/attribution.md). For commands executed
26
directly in the terminal (never in generated scripts, Terraform, or user code),
27
prefix `gcloud` with
28
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-cost-analysis)"`
29
and append `agent-skills/1.0 (skill:gke-cost-analysis)` to `User-Agent` headers.
30
31
## Overview
32
33
When users ask about GKE costs (e.g., "What are my costs across projects?",
34
"What's my most expensive namespace?", "Why is my cluster cost spiking?"), use
35
this skill to provide a structured and expert response using BigQuery billing
36
exports, cost allocation metadata, and live cluster metrics.
37
38
## Instructions
39
40
When handling a cost-related question:
41
42
1. **Provide a Direct Answer**: Address the specific cost question or
43
analytical request clearly and concisely.
44
2. **Explain BigQuery Integration**: Explain how to query BigQuery for
45
historical cost breakdown. Note that GKE costs originate from the GCP
46
Billing Detailed BigQuery Export (`gcp_billing_export_resource_v1_*`).
47
3. **Check & Verify Cost Allocation**: Explain that GKE Cost Allocation must be
48
enabled on the cluster (`--enable-cost-allocation`) for namespace, label,
49
and workload-level billing granularity. If queries return empty labels,
50
provide the `gcloud` command to enable it.
51
4. **Analyze Pricing Drivers & Utilization**: When diagnosing cost drivers,
52
explain whether the cluster is in Autopilot (billed by requested pod
53
CPU/memory) or Standard mode (billed by underlying VM node size + control
54
plane fees), and compare live utilization (`kubectl top`) against
55
provisioned requests.
56
5. **Provide Actionable Commands/Queries**: Provide concrete BigQuery CLI (`bq
57
query`) commands or read-only `gcloud`/`kubectl` inspection commands. Prefer
58
`bq` over BigQuery Studio when available.
59
60
## Key Points & Pricing Drivers
61
62
- **Data Source**: GKE costs come from GCP Billing Detailed BigQuery Export.
63
The user must provide the full path to their BigQuery table (dataset name
64
and table name containing the Billing Account ID).
65
- **Granularity Requirement**: GKE Cost Allocation
66
(`--enable-cost-allocation`) must be enabled on the cluster to populate
67
`goog-k8s-cluster-name`, `k8s-namespace`, `k8s-workload-name`, and
68
`k8s-workload-type` labels in BigQuery.
69
- **Autopilot vs. Standard Cost Drivers**:
70
- **Autopilot Pricing**: Billed directly on pod resource requests
71
(`requests.cpu`, `requests.memory`, ephemeral storage). Over-requested
72
pods drive up billing regardless of whether the pod actively uses those
73
CPU cycles or memory.
74
- **Standard Pricing**: Billed on provisioned node pool VMs (`e2`, `n4`,
75
`c3`, etc.). Idle nodes or multiple low-utilization dev clusters drive
76
excess infrastructure costs.
77
- **Cluster Management Fee**: ~$0.10/hour per cluster applies to BOTH
78
Standard and Autopilot modes. The free tier waives it for one eligible
79
cluster per billing account.
80
- **Credits & Discounts Impact**: When analyzing `cost` versus
81
`cost_before_credits`, note that Committed Use Discounts (CUDs) and Spot VMs
82
appear as credits or reduced rate charges in the billing export.
83
- **Tools & Syntax**: BigQuery CLI (`bq`) is preferred. When writing Standard
84
SQL queries, use a dot (`.`) instead of a colon (`:`) to separate the
85
project ID and dataset name (`{project_id}.{dataset_name}.{table_name}`).
86
- **Defaults**: Assume last 30 days, row limit 10, ordering by cost descending
87
(`ORDER BY cost DESC`), unless specified otherwise.
88
89
## Live Cluster & Cost Monitoring
90
91
Use read-only CLI commands to inspect current cluster budgets, node utilization,
92
and pod resource consumption vs. requests:
93
94
```bash
95
# View billing budgets for an account (requires Cost Management API)
96
gcloud billing budgets list --billing-account={billing_account} --quiet
97
98
# View live node resource utilization across the cluster
99
kubectl top nodes
100
101
# View pod resource usage across namespaces (compare against requested limits to diagnose waste)
102
kubectl top pods --all-namespaces --containers
103
```
104
105
> **Warning — cluster mutation, not read-only:** Enabling GKE cost allocation
106
> modifies the cluster. Get explicit user confirmation before running it, and
107
> note that namespace/workload labels populate in the billing export only from
108
> enablement onward (no historical backfill).
109
>
110
> ```bash
111
> gcloud container clusters update {cluster_name} \
112
> --enable-cost-allocation \
113
> --region {region}
114
> ```
115
116
## Applying Cost Optimizations
117
118
To apply rightsizing changes based on analysis (such as setting up `VPA`
119
recommendation mode, adjusting CPU/memory to `P95 * 1.2`, configuring Spot VMs
120
via `nodeSelector` or `ComputeClass`, enforcing `ResourceQuotas`, or selecting
121
machine types and CUDs), use the **`gke-cost-optimization`** skill.
122
123
## BigQuery Query Templates
124
125
Ready-to-adapt `bq query` templates — single workload cost, per-workload
126
per-cluster breakdown, per-namespace breakdown — with the placeholder policy
127
and defaults (30 days, `LIMIT 10`, `ORDER BY cost DESC`) are in
128
[references/billing-queries.md](references/billing-queries.md). All parameters
129
(dataset, table, project, cluster, etc.) must be replaced with user values.
130
131
Note: Checking that the `goog-k8s-cluster-name` label exists scopes the total
132
billing data specifically to GKE costs.
133

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…