Skip to content

fix(apisix-ingress-controller): restore the HPA template - #1031

Open
geographybuff wants to merge 1 commit into
apache:masterfrom
geographybuff:fix/ingress-controller-hpa
Open

geographybuff wants to merge 1 commit into
apache:masterfrom
geographybuff:fix/ingress-controller-hpa

Conversation

@geographybuff

Copy link
Copy Markdown

Closes #977.

The chart has autoscaling values and pdb.yaml reads them, but #837 removed templates/hpa.yaml during the v2 update, so autoscaling.enabled=true creates no HPA. The same PR dropped the check that stops the Deployment setting replicas under autoscaling. I found no reason recorded for either removal.

Changes:

  • add templates/hpa.yaml, modelled on the apisix chart's template
  • leave spec.replicas out of the Deployment when autoscaling is on, so helm upgrade doesn't reset what the HPA has set
  • add maxReplicas, targetCPUUtilizationPercentage and targetMemoryUtilizationPercentage to the values, and regenerate the README with helm-docs v1.11.0
  • bump the chart to 1.5.0

Decisions for review:

  • What extra replicas do. Only the leader reconciles. With 3 replicas, only the leader logged Starting workers, and a standby took over about 30 s after the leader pod was deleted. So this gives failover, not throughput, and the values comment says so. If you'd rather not offer an HPA for that reason, the alternative is to remove the autoscaling values and the matching branch in pdb.yaml.
  • autoscaling/v2 only. I left out the apisix chart's version value and its v2beta1 branch. autoscaling/v2 needs Kubernetes 1.23, and CI's matrix also lists 1.22, where turning this on would fail. The default is off, and CI's ct install step doesn't install this chart.
  • Defaults. maxReplicas is 3, not the apisix chart's 100, because of the leader behavior above. The CPU target is 80 and memory is off, matching this chart's template before feat: update ingress-controller to v2 #837. If both targets are 0, Kubernetes falls back to 80% CPU.

Behavior to expect:

  • Anyone already setting autoscaling.enabled=true gets an HPA after upgrading, and the chart stops setting replicas for them.
  • Without deployment.resources.requests, the HPA is created but can't compute utilization. It reports missing request for cpu in container manager and doesn't scale. The README says requests are needed.

Testing on k3d with k3s v1.35.5, 1 server and 1 agent, controller 2.2.0, adc 0.27.1. Scaling was triggered with a 1m CPU request and a 50% target, without real load:

Check Result
autoscaling.enabled=true on master No HPA, replicas set
Same on this branch 1 HPA, no replicas
Default values, master vs this branch No new resources. Besides a comment-only hpa.yaml document, only webhook.yaml differs, and it also differs between two renders of master because of its generated certificates
HPA with a CPU request Scaled from 1 to 3 within about 60 s, ScalingActive=True
Unrelated helm upgrade, Helm 3.16.4 and 4.3 spec.replicas stayed at 3
Same upgrade with master's deployment.yaml, Helm 4.3 spec.replicas dropped to 1
Upgrade from 1.4.1 with replicas=2, turning autoscaling on, Helm 3.16.4 HPA created. spec.replicas dropped to 1 right after the upgrade, then the HPA raised it
Turning autoscaling off with replicas=2, Helm 4.3 HPA removed, spec.replicas is 2
PDB with autoscaling Renders at minReplicas=2, not at 1
helm lint, ct lint v3.13.0 Pass

Not tested: real traffic load, a connected APISIX data plane, the admission webhook with several replicas, and Kubernetes versions other than 1.35.

AI disclosure: Claude Code wrote this change and this description, and ran the tests.

🤖 Generated with Claude Code

@moonming moonming left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed write-up and the k3d/upgrade testing, @geographybuff! The documentation of the leader-election behavior and the initial replica decrease is especially helpful.

Before merging, I think we need to settle the intended HPA semantics for this workload. With only the leader reconciling, CPU/memory utilization averaged across standby pods may not represent the actual capacity bottleneck. Scaling out can therefore reduce the average without adding reconciliation throughput. Let's get agreement on whether HPA is appropriate here, or whether fixed replicas plus a PDB are the better HA recommendation.

If we keep HPA, please add:

  1. Committed CI coverage for the HPA and Deployment behavior.
  2. A migration path for the initial replica decrease when autoscaling is first enabled.
  3. Handling for Kubernetes 1.22, since autoscaling/v2 requires 1.23+.
  4. Defaults for newly added values under --reuse-values. Simulating old coalesced values currently renders maxReplicas: null and metrics: null.

Please also rebase and use a version newer than the already-released chart 1.5.0. Your existing runtime evidence is valuable; the remaining work is to make the behavior and upgrades supportable. Thanks again!

The chart has autoscaling values and pdb.yaml reads them, but the v2 chart
update removed templates/hpa.yaml, so autoscaling.enabled=true creates no
HorizontalPodAutoscaler. That update also dropped the check that stops the
Deployment setting replicas under autoscaling, so restore both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@geographybuff
geographybuff force-pushed the fix/ingress-controller-hpa branch from 717076c to d4ab226 Compare November 26, 2026 19:23
@geographybuff

Copy link
Copy Markdown
Author

Rebased. Chart version 1.5.1. A maintainer can certainly pick a different chart version number at merge time, because the version might move before then.

Fixed replicas with PDB would be fine. Current main already features PDB, so using the PDB route would slim down this PR and keep the code base simpler. The biggest reason I went with HPA was because that was the spec that the issue asked for. So I'll wait for a maintainer to say the word before I switch to fixed replicas with PDB.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apisix-ingress-controller chart missing HPA template — autoscaling values have no effect

2 participants