Skip to content

fix(helm): two frontend replicas, never on the same node - #2342

Merged
lilyshen0722 merged 1 commit into
mainfrom
sre-frontend-two-replicas
Oct 19, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
sre-frontend-two-replicas

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Must merge before any Deploy Dev, including a Tuesday TASK-300 ship. The live frontend already runs this spec, applied by kubectl patch on 10-19; without this PR, the next Helm upgrade resets it to one replica.

Why. A spot reclaim took the single frontend replica down twice on 2026-10-19:

  • 15:19:34Z: the replacement had no node until a scale-up, so about 40 s;
  • 15:29:15Z: about 5 s.

Change.

  • The chart gains frontend.strategy and frontend.affinity, passed through as written. Both are empty in values.yaml, so the base render is unchanged.
  • values-dev.yaml sets:
    • replicaCount: 2;
    • a required pod anti-affinity on kubernetes.io/hostname for app: frontend. Two replicas never share a node, so the autoscaler keeps a second spot node and a reclaim leaves one replica serving;
    • RollingUpdate with maxSurge: 0, maxUnavailable: 1. The spot pool is capped at 2 nodes, so a surge pod would have nowhere to schedule and the rollout would hang; replacing one replica at a time keeps one serving.
  • CI's render-invariants step asserts all five dev values.

Checks.

  • helm template: the dev render has replicas 2, the strategy and the anti-affinity. The base render's frontend is unchanged (replicas 1, no strategy, no affinity).
  • The rendered dev frontend, converted with kubectl create --dry-run=client -o json, equals the live object field for field: replicas, strategy, affinity, nodeSelector and tolerations. So the next Helm upgrade changes nothing for the frontend.
  • Live rollout of the same spec (16:33:22Z):
    • The second pod was Pending until the autoscaler added spot node k6dn (about 30 s), then each replica was replaced in turn. It finished in about 66 s.
    • The pods sit on k6dn and 79t7.
    • https://commonly.me/ returned 200 on 39 of 39 two-second probes throughout.

Cost. A second spot n2-standard-2 while it runs, about $15/mo.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe

A spot reclaim took the single frontend replica down twice on 2026-10-19:
about 40 s at 15:19Z (the replacement waited for a node) and about 5 s at
15:29Z.

values-dev runs two replicas with a required hostname anti-affinity, so the
autoscaler keeps a second spot node and a reclaim leaves one replica
serving. The spot pool is capped at 2 nodes, so a surge pod would have
nowhere to go: a rollout replaces one replica at a time instead (maxSurge 0,
maxUnavailable 1). The chart gains frontend.strategy and frontend.affinity,
empty by default, and the CI render asserts the dev values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MCgCsf3UJRCPRbnNKxsECe

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gate review @ 4989d03: PASS.

What I checked

  • Template. frontend-deployment.yaml passes frontend.strategy through under spec and frontend.affinity under spec.template.spec. Both are wrapped in with, so the base values.yaml defaults ({}) render nothing, and other installs keep the Kubernetes defaults. The indentation matches the neighbouring tolerations block.
  • Anti-affinity selector. It selects app: frontend. commonly.frontend.selectorLabels (_helpers.tpl:78) puts that label on every frontend pod, so the rule matches its own replicas and nothing else.
  • Rollout. maxSurge: 0 with maxUnavailable: 1 replaces one replica at a time. With required hostname anti-affinity and the spot pool capped at two nodes, a surge pod would have nowhere to schedule. This shape can't deadlock, and one replica serves throughout.
  • Nothing else sets the frontend's replicas. No frontend HPA or PDB exists in the chart (only backend-hpa.yaml), so replicaCount: 2 is the whole story.
  • Live cluster (read-only): frontend is at replicas 2, surge/unavailable 0/1, topologyKey kubernetes.io/hostname. Its two pods are Ready on two different spot nodes. So this PR records what's already running, and Helm won't reset it to one replica on the next deploy.
  • CI guard. The new tests.yml assertions pin replicas, surge, unavailable, topologyKey and the selector label on the rendered dev chart, so a later values edit can't silently undo this.
  • Hygiene. The commit author is Lily with the noreply email. The head matches the branch (ls-remote), and CI is green at this head. The diff carries no project id or registry host: the image line it sits next to is the existing placeholder.

Residual (accepted, not a defect). If a spot node is reclaimed, the replacement replica stays Pending until the autoscaler supplies a second node. Until then the site runs on one replica, which is the state the single-replica config was in all the time.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit 9f03cce Oct 19, 2026
17 checks passed
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.

1 participant