Kubernetes · FinOps

One Reusable Plan/Apply Workflow for Cost-Optimised Autoscaling

A shared workflow registers clusters and applies autoscaling policy, parameterised by environment, HA role and state suffix: spot in lower, on-demand in upper.

  • CAST AI
  • Terraform
  • GitHub Actions
  • Helm
  • Vault
  • TFLint
  • Checkov

// Overview

Thin wrappers for teams and customers (lower, upper, HA primary and secondary) call one reusable workflow with a plan job followed by a gated apply job. Policy is read from Vault: lower uses spot capacity, upper on-demand; CPU, memory, disk and pod limits are set; evictor and weekly node rotation are Vault-controlled.

// The problem

Node scaling and cost tuning has to be consistent and re-runnable across many clusters and two environments without duplicating workflow logic.

// Flow

One Reusable Plan/Apply Workflow for Cost-Optimised Autoscaling flow1. Wrapper prepare → 2. Matrix of jobs → 3. Plan job → 4. Plan artifact → 5. Gate: changes only → 6. Apply or destroy → 7. Chain onward01Wrapper prepare02Matrix of jobs03Plan job04Plan artifact05 · GATEGate: changes only06Apply or destroy07Chain onward
  1. Wrapper preparedetermine environments and subscriptions; check the required flag
  2. Matrix of jobslower, upper, lower-secondary, upper-secondary, with paired skip jobs
  3. Plan jobfederated auth, templated backend with state suffix, fmt, init, validate, lint, scan
  4. Plan artifactmarkdown summary and raw plan uploaded; optional chat notification
  5. Gate: changes only gateapply runs only if the plan has changes and the action allows
  6. Apply or destroythe exact saved plan is applied
  7. Chain onwardTerraform dispatches the GitOps bootstrap

// Design decisions & guardrails

  • Applying the saved plan artifact guarantees that what was reviewed is what runs.
  • A state-suffix input separates HA secondary state; an is-secondary flag adjusts behaviour such as the evictor.
  • Auth method is an input (admin or RBAC) for clusters with local accounts disabled.
  • Evictor, rotation schedule and zones are all Vault-driven with documented defaults.
  • The earlier GCP generation did the same with a read-only mode and a GPU toggle.

// Outcome

Documented limits such as 2 to 200 CPU cores autoscaling, with one workflow serving every cluster shape.

// Related