โšก
Zero to Platform Architect2026
Phase 5: GitOps & Crossplane Control Planes
Phase 5: GitOps & Crossplane Control Planesโฑ๏ธ 10 min readโšก Staff SRE Standard
๐ŸŽฏ Foundations Test Bank →

Lesson 1: Enterprise GitOps & The ArgoCD App-of-Apps Architecture

๐Ÿง  The Concept (Explain Like Iโ€™m 5)

Imagine running a fleet of 50 high-end restaurants across the country:

  • The Traditional Push Model (The Chaos): Every time the executive chef changes a recipe, they have to personally dial 50 individual kitchen phones, give orders over the phone to line cooks, and hope no one misheard. If a line cook in Chicago secretly adds extra salt to the sauce, nobody in headquarters knows. If a hacker intercepts the phone line, they can order every kitchen to throw away the food.
  • The GitOps Pull Model (The Master Recipe Book): The executive chef writes the definitive recipe in a master digital notebook (Git Repository - Single Source of Truth). In every kitchen, an autonomous kitchen supervisor (ArgoCD) stares at the notebook 24/7. The second the chef updates the recipe, the supervisor instantly updates the kitchen line. If a cook in Chicago tries to secretly add extra salt, the supervisor immediately slaps their hand away and restores the exact original recipe (Automated Self-Healing).
  • The App-of-Apps Pattern: Instead of telling the supervisor to track 200 individual appetizer, entree, and dessert recipes one by one, the chef writes a single โ€œMenu of Menusโ€ (Root Application). The supervisor reads the Master Menu, which automatically imports and deploys all 200 dishes in strict sequence (Sync Waves)!

๐Ÿข The Enterprise Context: The OpenGitOps Standard

Enterprise platform engineering operates under the OpenGitOps Standards (governed by the CNCF):

  1. Declarative: The entire state of the system (infrastructure, networking, applications, policies) is described declaratively in YAML/HCL.
  2. Versioned and Immutable: State is stored in a version control system (Git) where every commit is cryptographically hashed, signed, and auditable.
  3. Pulled Automatically: Software agents running inside the cluster pull the desired state from Git, eliminating the need to expose cluster API ports to external CI/CD servers.
  4. Continuously Reconciled: Software agents continuously observe the actual live state and automatically reconcile any drift back to the desired state.
flowchart TD
    subgraph LegacyPush ["Traditional Push CI/CD (High Security Risk)"]
        Dev1["Developer"] --> Git1["Git"]
        Git1 --> CI1["CI Runner (GitHub Actions / Jenkins)"]
        CI1 -->|"Requires Cluster Admin Kubeconfig<br/>Direct Internet Ingress to Port 6443 โš ๏ธ"| Cluster1["Production EKS Cluster"]
    end

    subgraph ModernGitOps ["Enterprise GitOps Pull Architecture (Zero-Trust)"]
        Dev2["Developer"] --> Git2["Enterprise Git Fleet Repo<br/>(Single Source of Truth)"]
        subgraph Cluster2 ["Production EKS Cluster (Private VPC, No Inbound API)"]
            ArgoCD["<b>ArgoCD Controller</b><br/>Continuous 3-minute Reconcile Loop"]
            LiveK8s["Cluster Live State"]
        end
        Git2 -.->|"Outbound TLS Pull Only"| ArgoCD
        ArgoCD -->|"Self-Heals Drift"| LiveK8s
    end

๐ŸŒณ The App-of-Apps Architecture Under the Hood

In an enterprise with 50 clusters and 400 microservices, managing individual Application CRDs manually in the ArgoCD web UI is an anti-pattern. The App-of-Apps pattern uses Kubernetes recursion: a single Root Application creates other child Applications.

flowchart TD
    GitRepo["<b>Central Fleet Git Repo</b><br/>https://github.com/corp/gitops.git"]

    subgraph RootLevel ["Bootstrap Layer"]
        RootApp["<b>Root Application (App-of-Apps)</b><br/>path: /bootstrap/production"]
    end

    subgraph SyncWave0 ["Sync Wave -5: CRDs & Networking"]
        AppCilium["Cilium CNI Application"]
        AppCert["Cert-Manager Application"]
    end

    subgraph SyncWave1 ["Sync Wave 0: Platform Operators"]
        AppVault["External Secrets / Vault"]
        AppKarp["Karpenter Autoscaler"]
        AppProm["Prometheus Monitoring Stack"]
    end

    subgraph SyncWave2 ["Sync Wave 5: Business Services"]
        AppOrders["Order Microservice"]
        AppPayments["Payment Microservice"]
    end

    GitRepo -.->|"Watches"| RootApp
    RootApp -->|"Provisions"| AppCilium
    RootApp -->|"Provisions"| AppCert
    RootApp -->|"Provisions"| AppVault
    RootApp -->|"Provisions"| AppKarp
    RootApp -->|"Provisions"| AppProm
    RootApp -->|"Provisions"| AppOrders
    RootApp -->|"Provisions"| AppPayments

๐ŸŒŠ Mastering Sync Waves & Resource Hooks

In complex Kubernetes deployments, dependencies are strictly hierarchical:

  • You cannot deploy a Certificate before the Cert-Manager CRDs are registered.
  • You cannot deploy an Order Service before its PostgreSQL database schema migration runs.

ArgoCD solves this deterministically using Sync Waves and Resource Hooks.

The Sync Wave Mechanism

ArgoCD sorts all manifests in an application by their argocd.argoproj.io/sync-wave annotation (an integer from negative to positive, default 0).

  1. ArgoCD applies all resources in Wave -5.
  2. ArgoCD pauses and monitors the health status of Wave -5 resources.
  3. Only when all Wave -5 resources reach the Healthy state, ArgoCD proceeds to Wave 0.
  4. If any resource fails or health times out, the sync is halted immediately, protecting the cluster from cascading failures!
sequenceDiagram
    autonumber
    participant Argo as ๐Ÿš€ ArgoCD Controller
    participant K8s as โ˜ธ๏ธ Kubernetes API
    participant DBJob as ๐Ÿ—„๏ธ Migration Job (PreSync)
    participant Pods as ๐Ÿ“ฆ Workload Pods (Wave 1)

    Argo->>K8s: 1. Evaluates Wave 0: Namespaces & ConfigMaps
    K8s-->>Argo: Wave 0 Healthy โœ…
    Argo->>DBJob: 2. Launches PreSync Hook: Execute Flyway/Liquibase SQL Migration
    DBJob-->>Argo: Job Completed (Exit 0) โœ…
    Argo->>Pods: 3. Evaluates Wave 1: Deploys Workload Pods
    Pods-->>Argo: Pods Running & Ready โœ…
    Note over Argo,Pods: Zero-Downtime Migration & Deployment Complete!

๐Ÿ’ป Production Manifests: Root App & Sync Waves

1. The Root Application Manifest (root-application.yaml)

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: root-platform-application
  namespace: argocd
  # CRITICAL: Ensures child applications are safely deleted if removed from Git
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default
  source:
    repoURL: "https://github.com/my-enterprise-org/gitops-fleet.git"
    targetRevision: main
    path: bootstrap/production
  destination:
    server: "https://kubernetes.default.svc"
    namespace: argocd
  syncPolicy:
    automated:
      prune: true     # Automatically deletes cloud resources when removed from Git
      selfHeal: true  # Automatically overwrites out-of-band manual changes
    syncOptions:
      - CreateNamespace=true
      - ApplyOutOfSyncOnly=true
      - PruneLast=true # Deletes old resources only after new ones are healthy
    retry:
      limit: 5
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 3m

2. Child Application with Sync Wave (child-cert-manager.yaml)

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: cert-manager
  namespace: argocd
  annotations:
    # Wave -5 ensures Cert-Manager is fully running before application ingresses deploy
    argocd.argoproj.io/sync-wave: "-5"
spec:
  project: default
  source:
    repoURL: "https://charts.jetstack.io"
    chart: cert-manager
    targetRevision: "v1.14.4"
    helm:
      values: |
        installCRDs: true
  destination:
    server: "https://kubernetes.default.svc"
    namespace: cert-manager
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

3. Database Migration Job with PreSync Hook (db-migration.yaml)

apiVersion: batch/v1
kind: Job
metadata:
  name: order-service-db-migration
  namespace: workloads
  annotations:
    # Triggers before the new application version is deployed
    argocd.argoproj.io/hook: PreSync
    # Automatically cleans up successful jobs to prevent clutter
    argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: flyway-migration
          image: 123456789012.dkr.ecr.us-east-1.amazonaws.com/db-migrate:v2.1.0
          command: ["flyway", "migrate"]
          envFrom:
            - secretRef:
                name: db-credentials

๐Ÿ›ก๏ธ Preventing Configuration Drift & Ignoring Expected Dynamic Changes

While selfHeal: true is crucial for security, some Kubernetes resources have fields that are updated dynamically by in-cluster controllers (e.g. HPA updating replicas, or mutating webhooks injecting annotations).

Without ignoreDifferences, ArgoCD will perceive normal HPA autoscaling as โ€œConfiguration Driftโ€ and fight with the HPA in an infinite loop!

spec:
  ignoreDifferences:
    # Ignore HPA replica count adjustments
    - group: apps
      kind: Deployment
      jsonPointers:
        - /spec/replicas
    # Ignore dynamic AWS mutating webhook annotations
    - group: ""
      kind: ServiceAccount
      jsonPointers:
        - /metadata/annotations/eks.amazonaws.com~1token-expiration

๐Ÿงญ Step-by-Step Operational Playbook: Bootstrapping an EKS Cluster from Zero with ArgoCD App-of-Apps

Follow this step-by-step runbook to turn an empty Kubernetes cluster into a fully configured production platform using a single kubectl apply command:

Step 1: Install Hardened HA ArgoCD Control Plane

  1. Plain-English Goal: Deploy the multi-replica High-Availability ArgoCD manifest so the GitOps controller itself survives node failures.
  2. Action:
    kubectl create namespace argocd
    kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/ha/install.yaml
    kubectl wait --for=condition=Available deployment/argocd-server -n argocd --timeout=180s

Step 2: Assign Deterministic Sync Waves to Platform Add-Ons

  1. Plain-English Goal: Prevent race conditions (such as deploying an ExternalSecret before the external-secrets CRD exists) by annotating child Application manifests with ordered argocd.argoproj.io/sync-wave numbers:
    • Wave -2: Namespaces & CustomResourceDefinitions (CRDs)
    • Wave -1: Cilium CNI, Cert-Manager & External Secrets Operator
    • Wave 0: Karpenter, Ingress Controller & Prometheus Stack
    • Wave 1: Crossplane XRDs & Database Claims
    • Wave 2: Microservice Workloads

Step 3: Apply the Single Root Bootstrap Application

  1. Plain-English Goal: Apply the parent root-app.yaml once; ArgoCD recursively discovers and reconciles all child applications in gitops-fleet/bootstrap/.
  2. Action:
    kubectl apply -f bootstrap/root-application.yaml
    argocd app list

Step 4: Verify Self-Healing & Drift Remediation

  1. Plain-English Goal: Confirm that if an engineer manually edits a live Service or Deployment via kubectl edit, ArgoCD detects the drift and reverts the cluster back to the Git state within seconds.
  2. Action:
    argocd app wait root-platform-bootstrap --health --sync --timeout 300

๐Ÿ› ๏ธ Real-World Troubleshooting & Failure Modes

1. The Cascading Deletion Disaster

  • Symptom: An engineer accidentally deletes the root-platform-application manifest, and within 30 seconds, all 50 child applications, namespaces, databases, and microservices in production are purged!
  • Root Cause: The resources-finalizer.argocd.argoproj.io finalizer initiates a cascading deletion: when the parent application is deleted, ArgoCD recursively deletes all children.
  • Enterprise Prevention:
    1. Use ArgoCD Projects (AppProject) with strict destination restrictions.
    2. Implement GitHub branch protection requiring 2 senior architect approvals on the bootstrap/ directory.
    3. Apply argocd.argoproj.io/sync-options: Delete=false to mission-critical resources (Databases, PVCs, Namespaces).

2. โ€œComparisonError: Namespace does not existโ€

  • Symptom: ArgoCD fails to sync with ComparisonError: namespaces "workloads" not found.
  • Fix: Add CreateNamespace=true under syncOptions in the Application manifest, or create the Namespace in Sync Wave -10 explicitly.

๐Ÿ“ Knowledge Check & Real-World Interview Scenarios

โ“ Question 1: The Out-of-Sync Secret Incident

An infrastructure engineer discovers that a production secret was corrupted. In a rush, they update the Secret directly using kubectl edit secret app-secrets -n workloads. The cluster is managed by ArgoCD with automated: selfHeal: false.

What state will ArgoCD display in the dashboard? What will happen the next time a developer merges a trivial README commit to the repository?

โœ… Answer & Explanation
  1. ArgoCD State: ArgoCD will immediately display the Application status as Yellow / OutOfSync. It detects that the live cluster object does not match the Git commit SHA.
  2. The Disaster on Next Commit: Because selfHeal: false was set, ArgoCD did not overwrite the change immediately. However, the next time ANY developer merges a commit to main (even a README or unrelated microservice), ArgoCDโ€™s automated sync will trigger.
  3. Overwritten Secret: ArgoCD synchronizes the application to match the Git repository, instantly overwriting the manual kubectl edit and reverting the Secret back to the corrupted value, triggering an outage!
  4. The Lesson: In GitOps, all mutations must happen via Git. Direct cluster edits are strictly temporary illusions that will be erased on the next sync.

โ“ Question 2: Why Sync Waves Outperform InitContainers for DB Migrations

In early Kubernetes designs, developers ran database schema migrations inside an initContainer of the main application Pod.

List 3 severe operational flaws with using initContainers for database migrations that ArgoCD PreSync Hooks completely solve.

โœ… Answer & Explanation
  1. Race Conditions Across Concurrent Replicas: If a Deployment scales up 10 pods simultaneously, all 10 initContainers boot at the exact same millisecond and attempt to execute schema migrations against the database simultaneously, leading to database deadlocks and table corruption.
  2. Rollback Deadlocks: If an initContainer migration fails, the Pod enters CrashLoopBackOff. The old healthy pods have already begun terminating, leaving the application with zero healthy replicas handling traffic.
  3. How PreSync Hooks Solve It:
    • An ArgoCD PreSync Hook runs as a single, isolated Kubernetes Job (completions: 1). Only one migration process touches the database.
    • The new application Pods are never created until the PreSync Job exits with Code 0. If the migration fails, the existing production pods continue running untouched with zero downtime!