1
---
2
name: gke-workload-scaling-troubleshooting
3
metadata:
4
version: "1.0.1"
5
category: Containers
6
description: >-
7
Diagnoses GKE HorizontalPodAutoscaler (HPA) failures — metrics showing as
8
<unknown>, FailedGetResourceMetric / FailedGetScale / FailedComputeMetricsReplicas
9
events, missing Pod resource requests, custom/external metrics-pipeline breakage
10
(FailedGetExternalMetric / FailedGetCustomMetric, unavailable metrics adapter,
11
control-plane firewall blocking the adapter), HPA that won't scale up or down
12
(tolerance / stabilization window / unavailable rate metrics), scale-to/from-zero
13
problems, and slow HPA reaction on large clusters. Use when an HPA isn't scaling a
14
workload as expected or reports metric errors. Don't use for configuring or
15
authoring new HPA/VPA objects or scaling best practices (see the
16
gke-workload-scaling skill), or for Cluster Autoscaler / node-pool sizing.
17
---
18
19
# GKE Workload Scaling Troubleshooting Skill
20
21
Use this skill to systematically diagnose and resolve **HorizontalPodAutoscaler
22
(HPA) failures** on GKE — metrics reported as `<unknown>`, `FailedGet*` events,
23
missing resource requests, custom/external metrics-pipeline breakage, HPA that
24
refuses to scale up or down, scale-to/from-zero issues, and slow HPA reaction on
25
large clusters. This skill operates non-interactively and enforces a read-only
26
diagnostics boundary before proposing manifest or configuration corrections.
27
28
> For configuring HPA/VPA objects and scaling **best practices**, use the
29
> `gke-workload-scaling` skill instead. This skill focuses on **failure
30
> diagnosis**.
31
32
## Attribution
33
34
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
35
MUST read [Usage Attribution](references/attribution.md). For commands executed
36
directly in the terminal (never in generated scripts, Terraform, or user code),
37
prefix `gcloud` with
38
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-workload-scaling-troubleshooting)"`
39
and append `agent-skills/1.0 (skill:gke-workload-scaling-troubleshooting)` to `User-Agent` headers.
40
41
## 🔍 Diagnosis & Resolution Workflow
42
43
### Step 0: Non-Interactive Context Discovery & Dry-Run Fallback
44
45
1. **Parameter Extraction**: Extract required context (`project_id`,
46
`cluster_name`, `cluster_location`, `hpa_name`, `workload_name`,
47
`workload_namespace`) non-interactively from the user prompt, active
48
`SETTINGS.md`, or environment defaults:
49
50
- Default `workload_namespace` to `default` if omitted.
51
- Infer missing cluster parameters from the active environment (`kubectl
52
config current-context` or `gcloud config get-value project`).
53
54
2. **Cluster Credentials & Fallback Mode**:
55
56
- Attempt credential fetch: `gcloud container clusters get-credentials
57
{cluster_name} --location {cluster_location} --project {project_id}`.
58
- **Fallback / Dry-Run Mode**: If the cluster is unreachable,
59
non-existent, or live command execution fails (such as in sandboxed
60
evaluations, dry-run mode, or offline analysis):
61
- Limit retry attempts to avoid resource exhaustion and context
62
overflow.
63
- Immediately present the exact `kubectl` / `gcloud` diagnostic
64
commands for the human operator to run.
65
- Synthesize the root-cause analysis and output the proposed GitOps
66
correction based on the reported symptoms.
67
68
--------------------------------------------------------------------------------
69
70
### Step 1: Inspect the HPA and Classify the Symptom
71
72
Start every investigation with `kubectl describe hpa`, then route to the matching
73
branch. The three key sections are **`Metrics`** (an `<unknown>` value means the
74
HPA hasn't fetched the metric or the pipeline is broken), **`Conditions`**
75
(`AbleToScale`, `ScalingActive`, `ScalingLimited` — a `False` status marks a
76
failure), and **`Events`** (specific reasons such as `FailedGetScale` or
77
`FailedGetResourceMetric`).
78
79
**Diagnostic Commands:**
80
81
```bash
82
kubectl describe hpa {hpa_name} -n {workload_namespace}
83
kubectl get hpa {hpa_name} -n {workload_namespace} -o yaml
84
```
85
86
For historical events, query Cloud Logging (the HPA events survive after the live
87
`Events` list rolls over):
88
89
```
90
resource.type="k8s_cluster"
91
resource.labels.cluster_name="{cluster_name}"
92
resource.labels.location="{cluster_location}"
93
logName="projects/{project_id}/logs/events"
94
jsonPayload.involvedObject.kind="HorizontalPodAutoscaler"
95
```
96
97
Route by signal:
98
99
- **`FailedGetScale`, `FailedComputeMetricsReplicas`, `Error 400 ... label
100
is not allowed`, or fluctuating replicas from competing HPAs** → **Branch A**
101
(Configuration Errors).
102
- **`FailedGetResourceMetric`, `unable to fetch pod metrics`, or `multiple
103
services selecting the same target`** → **Branch B** (Workload & Service
104
Errors).
105
- **`<unknown>` custom/external metric, `FailedGetExternalMetric` /
106
`FailedGetCustomMetric`, or `no known available metric versions found`** →
107
**Branch C** (Metrics API & Data Availability).
108
- **Conditions all `True` / no errors but the workload won't scale up or down**
109
→ **Branch D** (Healthy but Unexpected Scaling).
110
- **Workload configured with `minReplicas: 0` won't scale to or from zero** →
111
**Branch E** (Scale To / From Zero).
112
- **Correct HPA but slow reaction on a cluster with many HPA objects** →
113
**Branch F** (Slow Recalculation on Large Clusters).
114
115
--------------------------------------------------------------------------------
116
117
### Step 2: Resolution — Route to the Matching Branch
118
119
Based on the signal you classified in Step 1, jump to **one** of the
120
mutually-exclusive branches below (A–F). These are alternatives — you do **not**
121
run them in sequence. After applying the branch's fix, go to Step 3 to present it
122
as a reviewable GitOps change.
123
124
#### Branch A: HorizontalPodAutoscaler Configuration Errors
125
126
- **`FailedGetScale` — `unable to get the target's current scale: ... "TARGET"
127
not found`**: the `scaleTargetRef` doesn't resolve to an existing scalable
128
workload.
129
130
- Verify the `scaleTargetRef` `name`, `kind`, and `apiVersion` exactly
131
match the target workload's metadata.
132
- Confirm the target workload exists **in the same namespace** as the HPA
133
(a missing `-n` puts objects in `default`, causing a mismatch).
134
- The target must be a scalable kind (Deployment, StatefulSet,
135
ReplicaSet) — you **cannot** autoscale a DaemonSet.
136
137
- **`FailedComputeMetricsReplicas` — `invalid metrics (1 invalid out of 1)`**:
138
the metric `type` and `target` don't match.
139
140
- If `type: Utilization`, the target must be `averageUtilization`.
141
- If `type: AverageValue`, the target must be `averageValue`.
142
143
- **`unable to fetch metrics from external metrics API: googleapi: Error 400:
144
Metric label: 'LABEL' is not allowed`**: an invalid key in
145
`metric.selector.matchLabels`.
146
147
- Remove or correct the disallowed label; find valid filterable labels in
148
the Cloud Monitoring metric documentation.
149
150
- **Replica count fluctuates / contradictory `SuccessfulRescale` events from
151
different HPAs**: more than one HPA targets the same workload via
152
`spec.scaleTargetRef`, and they compete. There is no dedicated condition for
153
this — confirm with `kubectl get hpa -n {workload_namespace} -o yaml` and
154
look for duplicate `scaleTargetRef` values.
155
156
- Consolidate all metrics into **one** HPA object (it takes the highest of
157
its `spec.metrics`) and delete the duplicates.
158
159
--------------------------------------------------------------------------------
160
161
#### Branch B: Workload & Service Errors
162
163
- **`ScalingActive: False`, reason `FailedGetResourceMetric`, message `unable
164
to compute the replica count`** (or a persistent `unable to fetch pod
165
metrics`): the HPA computes utilization as a percentage of the container
166
**resource request**, but at least one container in the Pod is missing a
167
`resources.requests` entry for the scaled resource (`cpu` or `memory`).
168
169
- Add `resources.requests` for the scaled resource to **every** container
170
in the Pod spec (including sidecars). A brief `unable to fetch pod
171
metrics` right after the metrics server starts is normal and self-heals.
172
173
- **`multiple services selecting the same target of HPA_NAME: SERVICE`**:
174
traffic-based autoscaling requires a **one-to-one** Service↔workload
175
relationship, but more than one Service's selector matches the workload's
176
Pods.
177
178
- Make the intended Service's selector unique (add a distinct label to the
179
workload and to that one Service), or tighten the other Services'
180
selectors so they no longer match the workload's Pods.
181
182
--------------------------------------------------------------------------------
183
184
#### Branch C: Metrics API & Data Availability (Custom / External Metrics)
185
186
The custom/external pipeline is: HPA controller → Kubernetes metrics API server
187
→ metrics adapter (for example `custom-metrics-stackdriver-adapter`) → metric
188
source (Cloud Monitoring / Prometheus). Symptoms are `<unknown>` metric values or
189
`FailedGetExternalMetric` / `FailedGetCustomMetric` events.
190
191
1. **Is the adapter registered and available?**
192
193
```bash
194
kubectl get apiservice | grep -E 'NAME|metrics.k8s.io'
195
```
196
197
Expect `v1beta1.custom.metrics.k8s.io` and/or
198
`v1beta1.external.metrics.k8s.io` with `AVAILABLE: True`. If `False`/missing,
199
the adapter is crashed or misconfigured — inspect its Pod logs in the
200
`custom-metrics` or `kube-system` namespace for permission, connectivity, or
201
"metric not found" errors.
202
203
2. **Query the metrics API directly** (bypasses the HPA to test the whole
204
pipeline; `jq` optional):
205
206
```bash
207
kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/{workload_namespace}/{metric_name}" | jq .
208
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/{workload_namespace}/pods/*/{metric_name}" | jq .
209
```
210
211
3. **Interpret the result:**
212
213
- **Valid JSON with a value** → the pipeline works; the fault is in the HPA
214
manifest (metric-name typo or wrong `matchLabels`).
215
- **`Error from server (Service Unavailable)`** → network isolation is
216
blocking the control plane from reaching the adapter. Add the adapter's
217
`targetPort` to the **control-plane firewall rule** (in addition to the
218
existing `tcp:443` and `tcp:10250`). Identify the rule with
219
`gcloud compute firewall-rules list --filter="name~gke-{cluster_name}-[0-9a-z]*-master"`,
220
and also confirm no NetworkPolicy blocks ingress to the adapter Pods.
221
- **Empty list `[]`** → the adapter runs but can't retrieve the metric.
222
Inspect the adapter Pod logs, and confirm in Metrics Explorer that the
223
metric actually exists in the source with the expected name and labels.
224
225
- **`unable to fetch metrics from custom metrics API: no known available metric
226
versions found`**: a communication breakdown (control plane briefly
227
unavailable during an upgrade/repair, or the adapter Pods are unhealthy or
228
not registered) — **not** a problem at the metric source. Check control-plane
229
health/notifications, confirm the adapter Pods are `Running` with no restarts
230
(`kubectl get pods -n custom-metrics,kube-system -o wide`), and re-verify the
231
APIServices are `AVAILABLE: True`. Often transient.
232
233
- **`googleapi: Error 400: The supplied filter ... will not return any time
234
series`**: the query is valid but no data matched (different from a value of
235
`0`) — the application wasn't writing the metric during the window. Verify the
236
metric name/labels match what the app emits, confirm the app had permission
237
and was active, and check the app logs for metric-emission errors.
238
239
--------------------------------------------------------------------------------
240
241
#### Branch D: Healthy but Unexpected Scaling Behavior
242
243
The HPA's conditions are `True` and it shows no errors, but scaling doesn't
244
happen as expected.
245
246
- **Won't scale up** — check, in order:
247
- **Replica limits**: `currentReplicas` is already at `minReplicas` /
248
`maxReplicas` (see the `ScalingLimited` condition); adjust the bounds.
249
- **Tolerance window**: Kubernetes ignores changes while the
250
current/target ratio stays within `0.9`–`1.1` (default **10%
251
tolerance**). Example: target 85% CPU, current 93% → ratio ≈ 1.094 < 1.1,
252
so no scale-up. Wait for the metric to move outside the band, or
253
configure a different tolerance.
254
- **Unready Pods**: `Pending`/not-`Ready` Pods are excluded from the
255
calculation — resolve the underlying scheduling/probe issue.
256
- **Sync delay**: a 15–30s delay between threshold crossing and action is
257
normal.
258
259
- **Won't scale down** — check, in order:
260
- **Multiple metrics**: the HPA uses the metric demanding the **most**
261
replicas, so it won't scale down unless **all** metrics agree.
262
- **Unavailable metric halts scale-down**: if any metric goes `<unknown>`
263
the HPA conservatively refuses to scale down. Common with **rate-based**
264
custom metrics that stop reporting at zero traffic. Prefer **gauge**
265
metrics (for example `num_undelivered_messages`) or make the source
266
publish `0` during inactivity rather than sending no data.
267
- **Scale-down stabilization window**: the default
268
`behavior.scaleDown.stabilizationWindowSeconds` is **300s (5 min)**.
269
Lower it if scale-down must be faster.
270
271
--------------------------------------------------------------------------------
272
273
#### Branch E: Scale To / From Zero (GKE 1.37+)
274
275
Scaling a workload to and from zero replicas with HPA (`minReplicas: 0`) is
276
supported on **GKE 1.37 or later**.
277
278
- **Won't scale to zero**:
279
- `minReplicas: 0` must be set.
280
- The HPA **cannot** scale to zero using only `Resource` (CPU/memory)
281
metrics — configure at least one `External` or `Object` metric.
282
- With multiple metrics, all must evaluate to zero.
283
- GKE waits the 5-minute scale-down stabilization window at zero demand
284
before going from 1→0.
285
- Any metric showing `<unknown>` pauses scale-down (see Branch D).
286
287
- **Won't scale up from zero**: run `kubectl describe hpa {hpa_name}` and check:
288
- **Metrics**: the value must be `> 0` and not `<unknown>`; if missing,
289
confirm the external source (for example Pub/Sub) is publishing and Cloud
290
Monitoring is receiving.
291
- **Conditions**: a healthy idle state shows `AbleToScale: True`,
292
`ScalingActive: True`, `ScaledToZero: True`. If `ScalingActive: False`
293
with reason `ScalingDisabledExternalScaleToZero` or
294
`ScalingDisabledReplicaCountZero`, the workload was **manually** scaled to
295
zero (for example `kubectl scale`), which pauses autoscaling. Resume it by
296
scaling the Deployment back to `--replicas=1`.
297
- Cold-start latency from node provisioning can add delay; Capacity Buffers
298
keep standby capacity ready.
299
300
--------------------------------------------------------------------------------
301
302
#### Branch F: Slow HPA Recalculation on Large Clusters
303
304
If HPAs are correct but react slowly, the cluster may exceed the HPA object count
305
the standard controller keeps within a 15-second recalculation period.
306
307
- Standard controller: within 15s for up to **300 HPA objects** (GKE 1.22+).
308
- **Performance HPA profile**: within 15s for up to **1,000 HPA objects** (GKE
309
1.31+) or **5,000 HPA objects** (GKE 1.33+, where it is enabled by default on
310
eligible clusters).
311
312
Enable it on an eligible cluster (this is a cluster mutation — present it for the
313
operator to run, don't execute it):
314
315
```bash
316
gcloud container clusters update {cluster_name} \
317
--location {cluster_location} --project {project_id} \
318
--hpa-profile=performance
319
```
320
321
Scaling on many metrics per HPA and slow (>~50 ms) custom-metric adapters also
322
lengthen the recalculation period. For visibility into scaling decisions, enable
323
HPA event logging and review the structured HPA decision logs.
324
325
--------------------------------------------------------------------------------
326
327
### Step 3: Propose the GitOps Correction
328
329
Enforce the read-only diagnostics boundary: **do not** apply live mutations. This
330
includes cluster/manifest changes (`kubectl edit`, `kubectl patch`, `kubectl
331
apply`, `kubectl scale`, `kubectl delete`) **and** Google Cloud / gcloud changes
332
(cluster updates such as `--hpa-profile`, and `gcloud compute firewall-rules`
333
updates). Instead, present the corrected HorizontalPodAutoscaler, PodSpec
334
(`resources.requests`), Service selector, workload autoscaling
335
configuration, or the `gcloud` command as a reviewable patch/command to be
336
applied through the user's GitOps pipeline (for example Config Sync, Argo CD, or
337
Flux) or by an authorized operator.
338
339
## References
340
341
- [Troubleshoot horizontal Pod autoscaling in GKE](https://docs.cloud.google.com/kubernetes-engine/docs/troubleshooting/horizontal-pod-autoscaling.md.txt)
342
- [Horizontal Pod autoscaling (concepts, Performance HPA profile & limits)](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/horizontalpodautoscaler.md.txt)
343
- [Configure horizontal Pod autoscaling (hpa-profile)](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/horizontal-pod-autoscaling.md.txt)
344
- [View horizontal Pod autoscaling events](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/view-horizontalpodautoscaling-events.md.txt)
345
- [Scale to and from zero using HPA](https://docs.cloud.google.com/kubernetes-engine/docs/tutorials/scale-to-from-zero-hpa.md.txt)
346
- [Kubernetes HorizontalPodAutoscaler (tolerance & scaling policies)](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/)
347