GKE Alert Configuration

GKE Alert Configuration

Writes Terraform and PromQL alerting policies for GKE clusters and workloads, covering the four golden signals, burn-rate SLO alerts, memory saturation and cluster health.

Skill files6 files

references/

scripts/

SKILL.md415 lines
1
---
2
name: gke-alert-configuration
3
metadata:
4
version: "1.0.3"
5
category: CloudInfrastructure
6
canonical_source: https://github.com/google/skills/tree/main/skills/cloud/gke-alert-configuration
7
description: >-
8
Configures alerting policies in Terraform for Google Kubernetes Engine (GKE)
9
clusters, workloads, and services using PromQL and Google Cloud Managed Service
10
for Prometheus. Use when writing, analyzing, validating, or deploying Terraform
11
alerting policies to monitor GKE service latency, traffic, error rates using
12
Multi-Window Multi-Burn-Rate SLO alerts, memory saturation, and cluster health
13
such as CrashLoopBackOff and Node NotReady conditions.
14
Don't use for non-GKE compute runtimes such as standalone Compute Engine VMs or
15
standalone Cloud Run services without GKE.
16
---
17
18
# GKE Alert Configuration
19
20
This skill provides guidelines and best practices for creating robust,
21
high-signal alerting policies for Google Kubernetes Engine workloads using
22
Google Cloud Managed Service for Prometheus and Terraform. It ensures
23
comprehensive coverage of the **4 Golden Signals** and key cluster health
24
metrics while minimizing alert noise.
25
26
--------------------------------------------------------------------------------
27
28
## Attribution
29
30
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
31
MUST read [Usage Attribution](references/attribution.md). For commands executed
32
directly in the terminal (never in generated scripts, Terraform, or user code),
33
prefix `gcloud` with
34
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-alert-configuration)"`
35
and append `agent-skills/1.0 (skill:gke-alert-configuration)` to `User-Agent` headers.
36
37
## Critical Rules
38
39
* **Negative Triggers and Scope Redirection for Non-GKE Standalone Runtimes**:
40
* This skill is strictly scoped to Google Kubernetes Engine (GKE)
41
workloads, clusters, and services using PromQL and Google Cloud Managed
42
Service for Prometheus.
43
* **Do not use for non-GKE compute runtimes**, such as standalone Compute
44
Engine virtual machines or standalone Cloud Run services without GKE.
45
* **STOP AND RESPOND DIRECTLY (Do Not Edit Files)**: When the user
46
requests alert configuration for non-GKE compute infrastructure:
47
1. **Do not write, create, edit, or validate any Terraform files on
48
disk**.
49
2. **Immediately stop and respond directly to the user in chat**:
50
* **Explicitly Clarify Out-of-Scope**: State clearly that
51
standalone Compute Engine virtual machine monitoring or
52
standalone Cloud Run monitoring is out of scope for this
53
GKE-specific PromQL alerting skill, which is designed
54
specifically for GKE workloads using Google Cloud Managed
55
Service for Prometheus and PromQL.
56
* **Do Not Generate GKE PromQL Alerts**: Do not create or generate
57
Kubernetes PromQL alert policies or fabricate Kubernetes
58
container, pod, or node resources for non-GKE infrastructure.
59
* **Redirect the User**: Guide and redirect the user to standard
60
Google Cloud Monitoring metrics, such as
61
`compute.googleapis.com/instance/cpu/utilization` or
62
`run.googleapis.com/request_latencies`, using standard
63
`google_monitoring_alert_policy` with `condition_threshold` or
64
MQL, or recommend the relevant specialized Cloud observability
65
skill.
66
* **Mandatory `kube-state-metrics` (KSM) Cost Guardrail**:
67
* Deploying open-source `kube-state-metrics` in Google Cloud Managed
68
Service for Prometheus incurs billable metric ingestion costs.
69
* **STOP AND ASK PERMISSION FIRST (Do Not Edit Files)**: When a requested
70
alert rule relies on **Tier 2 KSM metrics** (such as `kube_cronjob_*`,
71
`kube_pod_status_phase`, `kube_persistentvolume_*`, `kube_deployment_*`,
72
`kube_statefulset_*`, `kube_job_*`, or `kube_daemonset_*`), **do not
73
write, create, edit, or validate any Terraform files or generate alert
74
policies before obtaining user approval**.
75
* Instead, you **must immediately stop and respond directly to the user**
76
to:
77
1. **Alert the user** that the requested alert requires
78
`kube-state-metrics`.
79
2. **Explain the cost impact**: Detail that `kube-state-metrics` incurs
80
billable sample ingestion costs in Google Cloud Managed Service for
81
Prometheus.
82
3. **Ask for explicit permission**: Ask the user for explicit
83
permission before assuming, enabling, or generating KSM-dependent
84
alert configurations.
85
4. **Recommend filtering or allowlisting**: Suggest and recommend
86
filtering or allowlisting only the specific required metrics, such
87
as using a `PodMonitoring` resource with `metricRelabeling`
88
(`action: keep`) or KSM `--metric-allowlist` to minimize ingestion
89
costs. Provide a concrete allowlist example.
90
* **Always prefer Non-KSM Native Alternatives** (Tier 1 cAdvisor or native
91
GKE metrics documented in
92
[metrics_and_alerts_catalog.md](references/metrics_and_alerts_catalog.md))
93
whenever possible, such as using `container_memory_working_set_bytes`
94
and `container_spec_memory_limit_bytes` instead of
95
`kube_pod_container_resource_limits`.
96
* **Explicit Tier and Cost Surcharge Identification in Response**: In
97
every response where you generate or recommend an alerting policy, you
98
**must explicitly state its classification tier and cost impact**:
99
* **Tier 1 native or standard metric** (GKE built-in metrics, cAdvisor
100
`container_*`, kubelet volume stats, kubelet node conditions, and
101
control-plane metrics; see
102
[metrics_and_alerts_catalog.md](references/metrics_and_alerts_catalog.md)):
103
State that it is a **Tier 1 native or standard metric with zero KSM
104
cost surcharge**.
105
* **Tier 2 KSM metric**: State that it is a **Tier 2 KSM-dependent
106
metric** and follow the permission and allowlisting guardrail above.
107
*(Tip: Generally, metrics with the `kube_` prefix that represent
108
resource state or metadata belong to Tier 2).*
109
* **Plan-Validate-Execute Loop for Approved File Edits**: When modifying,
110
adding, or merging approved Terraform files on disk in a workspace, follow
111
the three-phase workflow:
112
1. **Plan**: Draft a structured change plan (`changes.json`) containing
113
proposed policy resource names, PromQL expressions, grouping labels, and
114
durations.
115
2. **Validate**: Run the pre-edit validation script (`python3
116
scripts/validate_config.py --plan changes.json`) to verify PromQL
117
grammar, lookback windows, duration rules, and ensure no duplicate
118
signals exist.
119
3. **Execute**: After the plan passes validation, apply or merge changes
120
in-place into the target Terraform configuration (`alerts.tf`).
121
4. *Note*: When answering questions or providing Terraform snippets
122
directly in chat where no disk modification is requested, output the
123
complete, valid Terraform HCL block in your response.
124
* **Configure the 4 Golden Signals and Cluster Health**: Always ensure the
125
target Kubernetes workload or service has the following alerting coverage:
126
1. **Latency** (P95 response time)
127
2. **Errors** (Multi-Window Multi-Burn-Rate SLO alerts, such as Fast Burn 1
128
hour / 5 minutes with factor 14.4, Slow Burn 6 hours / 30 minutes with
129
factor 6.0; do not use simple static ratios)
130
3. **Traffic** (Sudden drop or complete metric disappearance using
131
`absent()` or `default 0` syntax, or overload spikes)
132
4. **Saturation (Memory Limit Utilization Only)**: When describing or
133
configuring alert policies for a cluster or project, include ONLY
134
**Memory Saturation** (`container_memory_working_set_bytes` /
135
`container_spec_memory_limit_bytes`). Do **NOT** include CPU saturation
136
alerts or list `container_cpu_usage_seconds_total` as an alert metric
137
because CPU is compressible and throttled by CFS quotas rather than
138
causing uncompressible fatal termination (OOM).
139
5. **Cluster Health** (Pod CrashLooping, Node NotReady)
140
* **PromQL Only (Managed Prometheus)**: You must use
141
`condition_prometheus_query_language` with PromQL. Do **NOT** use MQL or
142
standard `condition_threshold` unless explicitly requested. Google Cloud
143
Managed Service for Prometheus is the standard telemetry ingestion path for
144
GKE.
145
* **Terraform Only**: Write the generated observability configuration ONLY as
146
Terraform (`.tf`) files, such as `alerts.tf` and `variables.tf`.
147
* **Dynamic Multi-Resource Alerting (No Hardcoding)**: You must not hardcode
148
specific pod names, node names, or service names in alerting conditions
149
unless explicitly requested. Alerting policies must be written to cover
150
resources dynamically:
151
* Always use grouping aggregations (`by (cluster, namespace, service, pod,
152
container)`) instead of filtering to a single instance. This allows a
153
single alert policy to dynamically track each service or pod separately.
154
* Always declare and use Terraform variables for `project_id`,
155
`cluster_name`, and `namespace` (`var.project_id`, `var.cluster_name`,
156
`var.namespace`) to make the configuration reusable across environments.
157
Always define these variables in `variables.tf` (or within the
158
configuration) and reference all three in policies or PromQL label
159
matchers.
160
* **No Redundant Duration Windows on Lookbacks**:
161
* When PromQL expressions already use an aggregated lookback window (such
162
as `increase(...[15m]) > 3` or multi-window SLO burn rates), the query
163
time window already smooths out transient spikes.
164
* Adding a Terraform duration on top of a PromQL lookback window increases
165
the Mean Time to Detect (MTTD) without providing additional smoothing
166
benefits.
167
* In these cases, set Terraform `duration = "0s"` (or `"60s"`). Do not
168
enforce `duration = "300s"` on top of `[15m]`, which delays critical
169
crashloop alerts by up to 20 minutes total (15 minutes + 5 minutes).
170
* Use `duration = "300s"` only on instantaneous gauge conditions, such as
171
`kube_node_status_condition == 0`.
172
* **Use SLO Burn Rates Instead of Simple Ratios**: For error rate alerting,
173
always generate Multi-Window Multi-Burn-Rate (MWMBR) SLO alerts (such as
174
14.4x burn rate over 1 hour and 5 minute windows for a 99% SLO) rather than
175
simple error rate ratios (`rate(5xx)/rate(total) > 0.05`), which produce
176
excessive false alarms on low traffic.
177
* **Robust Traffic Drop Detection (`absent()` / `default 0`)**: When
178
monitoring for traffic drops to zero, do not use `rate(...) == 0` alone
179
because Prometheus time series disappear completely when no requests occur
180
(evaluating to an empty vector rather than 0). Use `default 0` syntax, such
181
as `sum(rate(...[5m])) default 0 == 0`, or `absent(...) == 1`.
182
* **Notification Channels**: By default, never configure any notification
183
channels without user input. If the user explicitly provides a notification
184
channel, configure the alerts to use it. Otherwise, you must prompt the user
185
in your response to ask if they would like to configure one.
186
* **Consult GKE Metrics and Open-Source Alerts Catalog**: When designing or
187
generating evaluation suites or alerting policies, consult
188
[metrics_and_alerts_catalog.md](references/metrics_and_alerts_catalog.md)
189
for public GKE metrics (`kubernetes.io/`) and open-source Kubernetes alerts
190
(`awesome-prometheus-alerts`).
191
* **Plain English Response**: You must include a plain English explanation for
192
what the alerts do in your response. Explain what the alert measures, what
193
the threshold represents, and what a trigger indicates.
194
* **User Labels**: Include a `user_labels` block in all
195
`google_monitoring_alert_policy` resources to track policies created by this
196
skill:
197
198
```terraform
199
user_labels = {
200
created-with-google-skill = "gke-alert-configuration"
201
}
202
```
203
204
--------------------------------------------------------------------------------
205
206
## Alerting Policy Structure in Terraform
207
208
Alerting policies must be defined using the `google_monitoring_alert_policy`
209
resource with `condition_prometheus_query_language`. Always declare variables in
210
`variables.tf` for `project_id`, `cluster_name`, and `namespace`.
211
212
```hcl
213
# variables.tf
214
variable "project_id" {
215
type = string
216
description = "Google Cloud Project ID"
217
}
218
219
variable "cluster_name" {
220
type = string
221
description = "GKE Cluster Name"
222
}
223
224
variable "namespace" {
225
type = string
226
description = "Target Kubernetes Namespace"
227
default = "default"
228
}
229
230
variable "slo_target" {
231
type = number
232
description = "SLO Target fraction (for example 0.99 for 99%)"
233
default = 0.99
234
}
235
```
236
237
```hcl
238
# alerts.tf
239
# Example: Multi-Window Multi-Burn-Rate (MWMBR) SLO Alert (Fast Burn: 14.4x, 1h & 5m windows)
240
resource "google_monitoring_alert_policy" "k8s_service_error_rate_slo" {
241
project = var.project_id
242
display_name = "[K8s] ${var.cluster_name} - Service Error Rate SLO Fast Burn"
243
combiner = "OR"
244
245
conditions {
246
display_name = "Error Budget Fast Burn (14.4x over 1h and 5m)"
247
condition_prometheus_query_language {
248
query = <<-EOT
249
(
250
(
251
sum(
252
rate(
253
http_requests_total{
254
cluster="${var.cluster_name}",
255
namespace="${var.namespace}",
256
status=~"5.."
257
}[5m]
258
)
259
) by (service, namespace, cluster)
260
/
261
sum(
262
rate(
263
http_requests_total{
264
cluster="${var.cluster_name}",
265
namespace="${var.namespace}"
266
}[5m]
267
)
268
) by (service, namespace, cluster)
269
) > (1 - ${var.slo_target}) * 14.4
270
)
271
and
272
(
273
(
274
sum(
275
rate(
276
http_requests_total{
277
cluster="${var.cluster_name}",
278
namespace="${var.namespace}",
279
status=~"5.."
280
}[1h]
281
)
282
) by (service, namespace, cluster)
283
/
284
sum(
285
rate(
286
http_requests_total{
287
cluster="${var.cluster_name}",
288
namespace="${var.namespace}"
289
}[1h]
290
)
291
) by (service, namespace, cluster)
292
) > (1 - ${var.slo_target}) * 14.4
293
)
294
EOT
295
duration = "0s"
296
}
297
}
298
}
299
```
300
301
--------------------------------------------------------------------------------
302
303
## Telemetry Metrics and PromQL Examples
304
305
For GKE metrics (`kubernetes.io/`), community open-source alerts
306
(`awesome-prometheus-alerts`), KSM cost guardrails, and non-KSM native
307
alternatives, you must read and follow:
308
309
* [metrics_and_alerts_catalog.md](references/metrics_and_alerts_catalog.md)
310
311
For specific PromQL queries corresponding to each of the Golden Signals, you
312
must read and follow:
313
314
* [promql_queries.md](references/promql_queries.md)
315
316
For GKE cluster prerequisites, enabling Google Cloud Managed Service for
317
Prometheus collection, configuring PodMonitoring custom scraping, and enabling
318
control plane metrics collection (API Server, Controller Manager, Scheduler),
319
you must read and follow:
320
321
* [gke_configuration_prerequisites.md](references/gke_configuration_prerequisites.md)
322
323
--------------------------------------------------------------------------------
324
325
## Tooling Scripts and Validation Loop
326
327
Use the `validate_config.py` script to validate change plans and Terraform
328
configurations when working in a repository:
329
330
* **Pre-Edit Plan Validation**: Draft a `changes.json` plan specifying the
331
proposed policies, queries, and durations, and validate it before editing:
332
* Command: `python3 scripts/validate_config.py --plan changes.json`
333
* **Post-Edit and Directory Validation**: Scan existing or modified Terraform
334
files in a directory to ensure no duplicates or syntax errors exist:
335
* Command: `python3 scripts/validate_config.py --directory [TARGET_TF_DIR]
336
--cluster-var "${var.cluster_name}"`
337
* Single file validation: `python3 scripts/validate_config.py --file
338
[PATH_TO_TF_FILE]`
339
340
--------------------------------------------------------------------------------
341
342
## Technical Considerations and Gotchas
343
344
* **Lookback Windows versus Duration Buffers**:
345
* Do not add large `duration = "300s"` buffers to alerts that already use
346
aggregated lookback windows like `increase(...[15m])` or multi-window
347
SLO rates.
348
* The `[15m]` window in `increase(...[15m]) > 3` already smooths spikes.
349
Adding `duration = "300s"` increases MTTD by forcing the restart count
350
to remain above 3 for an extra 5 continuous minutes, delaying alerts by
351
up to 20 minutes total.
352
* Use `duration = "0s"` or `"60s"` when using lookback window functions.
353
Reserve `duration = "300s"` for raw instantaneous gauge conditions, such
354
as `kube_node_status_condition == 0`.
355
* **Memory Saturation Only for Cluster Alerting**:
356
* Do not configure CPU saturation alerts for cluster or workload
357
monitoring. CPU is compressible (throttled by the CFS scheduler), while
358
memory is uncompressible (triggers OOMKills).
359
* Configure Memory Saturation using `container_memory_working_set_bytes` /
360
`container_spec_memory_limit_bytes`.
361
* **Missing Resource Limits Blind Spot (Mandatory Explanation)**: Saturation
362
alerts that compare usage to limits (such as
363
`container_spec_memory_limit_bytes`) will **fail to resolve** or return
364
`NaN` if workloads do not have explicit Memory limits configured in their
365
Kubernetes manifests.
366
* **Mandatory Instruction**: Whenever you generate, discuss, or recommend
367
any memory saturation alert comparing usage against limits (including
368
non-KSM cAdvisor alternatives using
369
`container_spec_memory_limit_bytes`), you **must explicitly explain and
370
warn the user in your response** that container memory limits must be
371
explicitly configured in the Kubernetes pod specs or manifests
372
(`resources.limits.memory`) for the saturation query to resolve (and not
373
return `NaN` or fail to resolve).
374
* **Linear Disk Predictions (`predict_linear`)**: When forecasting volume
375
exhaustion using
376
`predict_linear(kubelet_volume_stats_available_bytes[6h:5m], 4 * 24 * 3600)
377
< 0`, explain that `predict_linear` uses linear regression over the recent
378
lookback window (for example, 6 hours) to project when available disk will
379
drop below 0 (for example, within 4 days). Identify
380
`kubelet_volume_stats_available_bytes` as a Tier 1 native kubelet metric
381
with zero KSM surcharge.
382
* **API Server Error and Client Metrics**:
383
* `apiserver_request_total` and `rest_client_requests_total` are Tier 1
384
Control Plane metrics with zero KSM cost surcharge. Explain that
385
`apiserver_request_total` monitors 5xx HTTP error rates across API
386
server endpoints, while `rest_client_requests_total` monitors 4xx and
387
5xx requests sent by REST clients communicating with the API server.
388
* **Traffic Disappearance Gotcha (`absent()` / `default 0`)**:
389
* When traffic drops completely to zero, Prometheus and GMP stop emitting
390
the `http_requests_total` time series.
391
* `sum(rate(...[5m])) == 0` evaluates to an empty vector, preventing the
392
alert from triggering.
393
* Always use `sum(rate(...[5m])) default 0 == 0` or `absent(...) == 1` to
394
reliably detect total traffic loss.
395
* **CrashLooping versus Normal Restarts**: A container restarting occasionally
396
might be normal, for example job completion or a minor rolling update. Alert
397
on **frequent** restarts (such as more than 3 restarts in 15 minutes with
398
`duration = "0s"`) using `kube_pod_container_status_restarts_total` rather
399
than a single restart to avoid noise.
400
* **Node Upgrades**: During GKE cluster upgrades, nodes are drained and
401
restarted, which can trigger "Node NotReady" alerts. Warn the user that
402
these alerts might fire during maintenance windows, or suggest configuring
403
maintenance windows if supported.
404
405
--------------------------------------------------------------------------------
406
407
## Additional Resources
408
409
* [Google Cloud Managed Service for Prometheus Documentation](https://docs.cloud.google.com/stackdriver/docs/managed-prometheus.md.txt)
410
* [GKE Observability and Monitoring Concepts](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/observability.md.txt)
411
* [Google Cloud Alerting Policies in Terraform](https://docs.cloud.google.com/monitoring/alerts/terraform.md.txt)
412
* [Google Cloud Monitoring Pricing](https://cloud.google.com/products/observability/pricing)
413
* [Google SRE Workbook: Alerting on SLOs](https://sre.google/workbook/alerting-on-slos/)
414
* [Awesome Prometheus Alerts Repository](https://github.com/samber/awesome-prometheus-alerts)
415

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