GitOps uses Git as the single source of truth for declarative infrastructure and applications. ArgoCD and Flux are the primary tools in the Kubernetes ecosystem.


Step 1 — ApplicationSets in ArgoCD

Managing dozens of clusters requires automation. ArgoCD ApplicationSets allow you to deploy apps to multiple clusters based on Git directories or cluster labels.

appset.yamlyaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
spec:
  generators:
  - clusters: {}
  template:
    metadata:
      name: '{{name}}-guestbook'
    spec:
      project: default
      source:
        repoURL: https://github.com/argoproj/argocd-example-apps.git
        targetRevision: HEAD
        path: guestbook
      destination:
        server: '{{server}}'
        namespace: guestbook

Step 2 — Drift Reconciliation

If someone manually uses kubectl edit, ArgoCD detects the 'drift' and automatically rolls it back to match the Git state, ensuring strict consistency.

GitOps Best Practices

  • Separate Code & Config: Keep application source code and deployment manifests in separate repositories.
  • Automated Image Updates: Use ArgoCD Image Updater to deploy new container images automatically.
  • Self-Healing: Enable auto-sync to aggressively overwrite manual cluster modifications.