Kubernetes · GitOps
Who Deploys the Deployer? Terraform-Bootstrapped FluxCD
Terraform installs the six Flux controllers on a fresh cluster and seeds per-cluster GitOps config from templates; Flux then manages the cluster and itself.
// Overview
The bootstrap workflow generates a per-cluster config directory from shared templates (pruning optional parts by feature flag), opens an auto-merged PR, then runs Terraform to bootstrap Flux and patch controllers. A lock file stops later runs regenerating customised config. Controllers authenticate to Git with a GitHub App and to the cloud with workload identity.
// The problem
Without GitOps, deployments are manual kubectl with no audit trail. But Flux cannot deploy itself, so a repeatable bootstrap is needed that never clobbers team customisations on re-run.
// Flow
- Triggerafter autoscaling, or manually; concurrency per team and environment
- Prepareread 20+ Vault values, resolve six controller identities
- Lock check gateif a bootstrap lock exists, skip config generation
- Generate configcopy template base, prune optional directories, substitute variables
- PR to GitOps repoauto-merged; repeated for the HA secondary
- Terraform applymatrix over lower, upper, primary, secondary
- Controller patchesconcurrency, resource limits, affinity, identity annotations
- Create lockcommitted per cluster
- Steady stateFlux reconciles every 60 seconds; rotation flows through Vault
// Design decisions & guardrails
- Bootstrap lock: the first run generates, later runs only reconcile controller patches; delete the lock to regenerate.
- Template system with conditional pruning by feature flag (HA, monitoring, mesh mode).
- Git authentication via GitHub App, with PAT fallback gated per cluster by a Vault key.
- Workload identity on every controller instead of static cloud credentials.
- Controller settings are Terraform patches rather than a template so they can be reconciled on every run.
- HA uses separate state per cluster and separate key suffixes for the secondary.
// Outcome
Six controllers per cluster, reconciling every 60 seconds, with no hand-run bootstrap.