agentleFS
scitixscitix/siclaw/skills/core/hpa-debug/SKILL.md

hpa-debug

Skill235 starsChanged 6 months agoApache-2.0View on GitHub

Diagnose HorizontalPodAutoscaler failures (not scaling, metrics unavailable, target mismatch). Checks HPA status, metrics-server health, and scaling events to identify why autoscaling is not working.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 6 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When a HorizontalPodAutoscaler is not scaling as expected — stuck at min/max replicas, showing <unknown> metrics, or not responding to load …

    line 10
  2. Distinctive:

    If no pods are found, try:

    line 44
  3. Distinctive:

    Verify metrics-server is serving data:

    line 50
  4. Very specific:

    If kubectl top returns error: Metrics API not available, metrics-server is not working.

    line 56
  5. Distinctive:

    If requests are not set, the HPA cannot calculate utilization percentages.

    line 66
  6. Very specific:

    Check the reason in kubectl describe hpa:

    line 90
  7. Very specific:

    If the HPA is stuck at maxReplicas and load is still high, advise the user to increase maxReplicas or investigate why the application needs …

    line 106
  8. Distinctive:

    Check the events for rapid scale-up/scale-down cycles.

    line 114
  9. Distinctive:

    Verify the actual pod resource usage:

    line 132
  10. Distinctive:

    Only one HPA should target a given Deployment/StatefulSet.

    line 146
  11. Very specific:

    Check if multiple HPAs reference the same scaleTargetRef.

    line 152
  12. Very specific:

    If the target Deployment is managed by ArgoCD or Helm, the HPA replica count may be overwritten on sync — check if the Deployment's …

    line 159

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

HPA Autoscaling Failure Diagnosis

When a HorizontalPodAutoscaler is not scaling as expected — stuck at min/max replicas, showing <unknown> metrics, or not responding to load — follow this flow to identify the root cause.

Scope: This skill is for diagnosis only. Once you identify the root cause, report it to the user and stop. Do NOT attempt to modify HPA settings, resource requests, or metrics configuration — that should be left to the user.

Diagnostic Flow

1. Check HPA status

kubectl get hpa <hpa-name> -n <ns>

Note:

  • TARGETS — current value vs target (e.g., 80%/50%). If showing <unknown>/50%, metrics are unavailable.
  • MINPODS / MAXPODS — scaling bounds
  • REPLICAS — current replica count

2. Describe the HPA

kubectl describe hpa <hpa-name> -n <ns>

Focus on:

  • Conditions — look for AbleToScale, ScalingActive, and ScalingLimited with their status and reason
  • Events — scaling decisions, metric fetch errors, or rate-limiting messages
  • Metrics — each metric's current value, target, and type (resource, custom, external)

3. Check metrics-server health

kubectl get pods -n kube-system -l k8s-app=metrics-server -o wide

If no pods are found, try:

kubectl get deployment -n kube-system metrics-server

Verify metrics-server is serving data:

kubectl top pods -n <ns>

If kubectl top returns error: Metrics API not available, metrics-server is not working.

4. Check target resource requests

HPA with CPU/memory percentage targets requires resources.requests to be set on the target containers.

kubectl get deployment <target-name> -n <ns> -o jsonpath='{range .spec.template.spec.containers[*]}{.name}: cpu={.resources.requests.cpu} memory={.resources.requests.memory}{"\n"}{end}'

If requests are not set, the HPA cannot calculate utilization percentages.

5. Match patterns and conclude


<unknown> metrics — Metrics not available

The HPA cannot fetch metrics for one or more targets.

Common causes:

  • metrics-server not installed or not running — check step 3
  • metrics-server not ready yet — it may take a few minutes after startup to collect data
  • No resource requests set — CPU/memory percentage targets require resources.requests on the target pods (step 4)
  • Custom metrics adapter missing — if the HPA uses custom or external metrics, the corresponding adapter (e.g., Prometheus adapter) must be installed

Advise the user to check metrics-server health and ensure resource requests are set.


ScalingActive: False — HPA cannot scale

The HPA has been disabled or cannot function.

Check the reason in kubectl describe hpa:

  • FailedGetResourceMetric — cannot fetch resource metrics (metrics-server issue)
  • FailedGetExternalMetric — cannot fetch external metrics (adapter issue)
  • InvalidMetricSourceType — the metric source type is not recognized

ScalingLimited: True — At min or max replicas

The HPA wants to scale but is constrained by minReplicas or maxReplicas.

Check the reason:

  • TooFewReplicas — HPA wants to scale down below minReplicas
  • TooManyReplicas — HPA wants to scale up above maxReplicas
  • DesiredWithinRange — current replicas are within bounds (normal)

If the HPA is stuck at maxReplicas and load is still high, advise the user to increase maxReplicas or investigate why the application needs so many replicas (possible performance issue).


HPA flapping (scaling up and down repeatedly) — Unstable metrics

The HPA keeps oscillating between replica counts.

Check the events for rapid scale-up/scale-down cycles. Common causes:

  • Metric target too close to normal usage — small load changes trigger scaling
  • Application slow to start — new pods take time to become effective, causing the HPA to scale up further before they help

The HPA has a default stabilization window (5 minutes for scale-down). Check if custom behavior is set:

kubectl get hpa <hpa-name> -n <ns> -o jsonpath='{.spec.behavior}'

Advise the user to adjust the stabilization window or the target utilization.


HPA not scaling up under load — Target not reached

The HPA sees metrics below the target threshold, so it does not scale.

Verify the actual pod resource usage:

kubectl top pods -n <ns> -l <selector>

Compare with the HPA target. If actual usage is below the target even under load:

  • The resource requests may be set too high (actual usage is a low percentage of requests)
  • The metric source may not reflect actual load

Multiple HPAs targeting the same workload — Conflicting autoscalers

Only one HPA should target a given Deployment/StatefulSet. Multiple HPAs on the same target cause unpredictable behavior.

kubectl get hpa -n <ns>

Check if multiple HPAs reference the same scaleTargetRef. Advise the user to consolidate into a single HPA with multiple metrics.

Notes

  • HPA evaluates metrics every 15 seconds by default (controlled by --horizontal-pod-autoscaler-sync-period on the controller manager).
  • Scale-down has a default stabilization window of 5 minutes to prevent flapping. Scale-up defaults to 0 (immediate).
  • For HPAs using autoscaling/v2, multiple metrics can be specified. The HPA scales to the highest recommended replica count across all metrics.
  • If the target Deployment is managed by ArgoCD or Helm, the HPA replica count may be overwritten on sync — check if the Deployment's replicas field is managed externally.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.