As infrastructure grows, managing Kubernetes clusters with imperative tools (kubectl apply) invites configuration drift and operational outages. We migrated our fleet of 15 production clusters to a fully declarative GitOps model.
This post walks through how we structured our repositories, handled secrets, and configured reconciliation loops across Core Inference and data infrastructure.
Repository Layout
Instead of a single monorepo containing everything, we separated our GitOps configuration into three distinct repositories to enforce RBAC and blast-radius boundaries:
infra-platform: Houses cluster definitions, network topologies, DNS zones, and core operators (Flux, Cert-Manager, ExternalDNS).infra-tenant-apps: Contains team-specific application deployments (Deployments, Services, Ingresses, Kustomizations).app-source-codes: Application source repositories that publish immutable container digests.
Within the GitOps repositories, each cluster reconciles its overlays via a Flux Kustomization resource using the GA v1 API and SOPS decryption enabled:
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: core-services-overlay
namespace: flux-system
spec:
interval: 5m0s
path: ./clusters/prod-eu/overlays
prune: true
sourceRef:
kind: GitRepository
name: infra-tenant-apps
decryption:
provider: sopsStandard base manifests are reused across environments while cluster-specific overlays patch resource limits, hostnames, and feature flags cleanly.
Handling Secrets Securely
GitOps requires committing every resource configuration to Git, which raises a hard question: how do we store secrets like PostgreSQL credentials or API keys?
We chose SOPS combined with GCP KMS. SOPS encrypts only the value fields matching encrypted_regex (such as ^(data|stringData)$), leaving keys readable for code review without exposing plaintext.
At runtime, Flux's kustomize-controller decrypts the manifest in memory before applying it to the API server:
apiVersion: v1
kind: Secret
metadata:
name: database-credentials
namespace: database
type: Opaque
stringData:
password: ENC[AES256_GCM,data:90kE4z8wT4e...,type:str]
sops:
gcp_kms:
- resource_id: projects/prod-infra/locations/global/keyRings/sops/cryptoKeys/flux
encrypted_regex: ^(data|stringData)$
mac: ENC[AES256_GCM,data:a8F1c2...,type:str]
version: 3.8.1Preventing Controller Fights with HPAs
One common GitOps pitfall is the reconciliation loop fighting runtime controllers. If a Deployment manifest in Git hardcodes spec.replicas: 3 while a Horizontal Pod Autoscaler (HPA) scales it to 12 during a traffic spike, the next reconciliation cycle can reset the fleet back to 3 and trigger an outage.
We resolved this using Kubernetes Server-Side Apply (SSA) semantics (Flux's default):
- Omit
spec.replicascompletely from Git manifests for HPA-managed Deployments—never set it to0, which explicitly scales the workload down to zero pods and disables standard HPA scaling. - Because
spec.replicasis absent from Flux's managed fields, the HPA controller retains sole ownership of the replica count while Flux continues reconciling image tags, env vars, and resource limits without conflict.