GKE Cost Optimization

GKE Cost Optimization

Reduces GKE costs by rightsizing workloads, using Spot VMs and committed discounts, and setting up cost allocation and resource quotas.

Skill files5 files

assets/

references/

SKILL.md187 lines
1
---
2
name: gke-cost-optimization
3
description: >-
4
Optimizes GKE costs, rightsizes workloads, and configures Spot VMs, CUDs, cost
5
allocation, and resource quotas. Use when optimizing GKE cluster or workload
6
costs, configuring GKE cost allocation or quotas, rightsizing CPU/memory
7
requests, or selecting Spot VMs and machine types. Don't use for general
8
compute class provisioning or GPU Selection (use gke-compute-classes instead).
9
metadata:
10
version: "1.0.2"
11
category: CloudObservabilityAndMonitoring
12
---
13
14
# GKE Cost Optimization
15
16
This reference covers strategies and workflows for reducing Google Kubernetes
17
Engine (GKE) costs while maintaining a secure and reliable posture.
18
19
## Attribution
20
21
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
22
MUST read [Usage Attribution](references/attribution.md). For commands executed
23
directly in the terminal (never in generated scripts, Terraform, or user code),
24
prefix `gcloud` with
25
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-cost-optimization)"`
26
and append `agent-skills/1.0 (skill:gke-cost-optimization)` to `User-Agent`
27
headers.
28
29
## Workflows & Optimization Strategies
30
31
### 1. Prerequisite: Cost Allocation & Monitoring
32
33
To enable GKE cost allocation (`--enable-cost-allocation`) for billing tracking
34
across namespaces and labels, inspect live cluster utilization (`kubectl top`),
35
or run historical cost breakdown queries in BigQuery (`bq`), use the
36
**`gke-cost-analysis`** skill. Once tracking is active and waste is diagnosed,
37
apply the optimization workflows below.
38
39
### 2. Configure Resource Quotas
40
41
Resource quotas restrict total resource consumption across tenants in
42
multi-tenant clusters, preventing runaway costs. Template:
43
[assets/resource-quota-example.yaml](assets/resource-quota-example.yaml)
44
(set namespace + `hard` limits, then `kubectl apply -f`).
45
46
### 3. Pod Rightsizing (VPA & MPA)
47
48
Adjust pod resource requests to match actual utilization. Over-provisioned
49
requests are one of the largest sources of waste.
50
51
- **Use VPA in Recommendation Mode** (`updateMode: "Off"` — recommends
52
without evicting):
53
54
```bash
55
# 1. Deploy VPA in recommendation mode (template: assets/vpa-recommendation-mode.yaml)
56
kubectl apply -f assets/vpa-recommendation-mode.yaml
57
# 2. Wait 24+ hours for data collection, then read recommendations
58
kubectl get vpa {deployment_name}-vpa -o jsonpath='{.status.recommendation}'
59
```
60
61
- **Optimization Rules:**
62
63
Condition | Action | Savings
64
----------------------------- | ---------------------------------- | -------
65
CPU request >5x P95 actual | Reduce to `P95 * 1.2` | High
66
Memory request >3x P95 actual | Reduce to `P95 * 1.2` | High
67
CPU request >2x P95 actual | Reduce to `P95 * 1.2` | Medium
68
No resource requests set | Add requests (enables bin-packing) | Medium
69
70
- **Use MPA**: Reconcile HPA and VPA recommendations when scaling both
71
horizontally and vertically to avoid conflicting scale events.
72
- **Review Cost Recommendations**: Check Google Cloud Console (`Cost
73
Management` > `GKE Cost Optimization`) for built-in rightsizing suggestions.
74
75
### 4. Spot VMs via ComputeClasses & NodeSelector
76
77
Use Spot VMs for fault-tolerant workloads to achieve 60-90% cost reduction.
78
79
#### 4.1 ComputeClass Configuration
80
81
For a Spot-first ComputeClass with On-Demand fallback (priority ordering,
82
`activeMigration`, machine family selection), use the **`gke-compute-classes`**
83
skill — ComputeClass YAML generation and priority configuration are its domain,
84
not this skill's.
85
86
#### 4.2 Direct Workload Spot Selection (`nodeSelector`)
87
88
For stateless or batch workloads in GKE Autopilot, target Spot capacity directly
89
using `nodeSelector`:
90
91
> [!WARNING] **Preemption Warning**: Spot VMs are interruptible and can be
92
> preempted at any time with a 30-second notice. Workloads must be
93
> fault-tolerant and run with at least 2 replicas for high availability. Always
94
> explicitly warn users about this preemption risk when recommending Spot VMs.
95
96
The exact Pod-level selector is:
97
98
```yaml
99
nodeSelector:
100
cloud.google.com/gke-spot: "true"
101
```
102
103
Full worked Deployment (replicas >= 2, `terminationGracePeriodSeconds: 25`,
104
`preStop` hook): [assets/spot-deployment-example.yaml](assets/spot-deployment-example.yaml).
105
106
**Spot-Suitable Workloads:**
107
108
Workload | Spot-Suitable?
109
--------------------------------- | ---------------
110
Batch / data processing | Yes
111
Dev / test environments | Yes
112
Stateless web/API (replicas >= 2) | Yes (with PDBs)
113
Jobs with checkpointing | Yes
114
Stateful workloads (databases) | No
115
Single-replica critical services | No
116
117
### 5. Machine Type Selection
118
119
When choosing node shapes or configuring ComputeClasses:
120
121
| Family | Use Case | Relative Cost |
122
| ------------- | ------------------------------------------------- | ------------- |
123
| e2 | General purpose, burstable | Lowest |
124
| t2a / t2d | Scale-out (Arm/AMD), price-performance optimized | Low |
125
| n4a | Axion Arm-based, general-purpose price-performance | Low |
126
| n4 / n4d | General purpose (Intel/AMD), flexible shapes | Low-Medium |
127
| c4a | Axion Arm-based, general-purpose, high efficiency | Medium |
128
| c3 / c4 | Compute-optimized (Intel) | Medium-High |
129
| c3d / c4d | Compute-optimized (AMD), high throughput | Medium-High |
130
| ek-standard | Autopilot enhanced | Medium |
131
| m3 / x4 | Memory-optimized, SAP HANA, large databases | High |
132
| g2 (L4 GPU) | AI inference | High |
133
| a3 (H100 GPU) | AI training | Highest |
134
| a4 / a4x | Ultra-scale AI (Blackwell GPUs) | Highest |
135
136
### 6. Committed Use Discounts (CUDs)
137
138
For steady-state workloads with predictable baseline usage, purchase 1-year or
139
3-year CUDs:
140
141
- **Resource-based CUDs** (committed to a machine family/region): roughly
142
high-30s% discount for 1-year, ~55% for 3-year (varies by machine family).
143
- **Flexible CUDs** (spend-based, portable across families/regions): lower
144
discounts (~28% 1-year, ~46% 3-year) in exchange for flexibility.
145
- **Autopilot:** Autopilot-specific CUDs were retired in January 2026 — new
146
commitments covering Autopilot usage are spend-based Compute Flexible CUDs
147
(existing Autopilot CUD commitments run out their term).
148
- Applied automatically to matching usage across the region.
149
- Purchase via Google Cloud Console > Billing > Committed use discounts.
150
151
**Size the commitment to the steady-state baseline only.** A commitment bills
152
for the full term whether or not you use it, so over-committing to peak usage
153
converts a discount into waste. Measure the floor of actual usage over a
154
representative period, commit to that, and cover everything above it with the
155
elastic options already in this skill:
156
157
- **Baseline** (always running) → resource-based CUDs.
158
- **Variable / bursty** → autoscaling on on-demand capacity.
159
- **Interruption-tolerant** (batch, CI, stateless workers) → Spot VMs, which
160
stack with autoscaling and need no commitment.
161
162
When recommending CUDs, state the split explicitly rather than implying the
163
whole footprint should be committed.
164
165
### 7. Cluster Management & Multi-Tenancy
166
167
- **Idle dev clusters**: GKE has no stop/start operation, and the cluster
168
management fee accrues as long as the cluster exists. To cut idle costs,
169
scale node pools to zero (`gcloud container clusters resize {cluster_name}
170
--node-pool {pool_name} --num-nodes 0`) or delete and recreate the cluster
171
via IaC (Terraform/Config Connector).
172
- **Right-size node pools (Standard)**: Use Cluster Autoscaler with
173
appropriate min/max limits.
174
- **Cheap warm headroom instead of overprovisioned nodes**: Standby capacity
175
buffers (GKE 1.37.1-gke.3020000+) keep pre-initialized nodes
176
suspended — you pay only disk + IP instead of full node price, with ~30s
177
resume. See the **`gke-cluster-autoscaler`** skill.
178
- **Multi-tenant consolidation**: Share a single cluster across multiple
179
engineering teams instead of maintaining per-team clusters, using Namespaces
180
and ResourceQuotas to isolate workloads.
181
182
## Cost & Utilization Monitoring
183
184
To inspect live node/pod utilization (`kubectl top nodes/pods`), view cluster
185
cost budgets (`gcloud billing budgets list`), or query detailed billing reports
186
in BigQuery (`bq query`), refer to the **`gke-cost-analysis`** skill.
187

© 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…