GitOps with Argo CD and Flux

Advanced · 10 min

Make a Git repository the source of truth for a cluster: an agent inside it pulls changes, applies them, reverts drift, and a rollback is just git revert.

Before thisPackaging Kubernetes apps with Helm and KustomizeContinuous delivery vs continuous deploymentInfrastructure as code: declarative vs imperative

Vishakha Sadhwani · 10 min

GitOps with Argo CD and Flux

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Vishakha SadhwaniReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • In GitOps the desired state of a system lives in Git, and an agent continuously makes the live system match it. Changes happen by commit, not by running commands against the cluster.
  • The agent runs inside the cluster and pulls from Git, so CI no longer needs credentials to the cluster. It only needs to commit a new image tag or digest.
  • Because the agent keeps reconciling, a manual change to the cluster is detected as drift and, with self-heal on, reverted to what Git says.
  • Deploy history is Git history: every release is a commit with an author and a review, and rolling back is a git revert.
  • Argo CD centres on an Application object and a web UI. Flux is a set of controllers driven by GitRepository and Kustomization objects. Both do the same core job.

Who changed production?

The notes API’s pipeline ends with a job that runs kubectl apply -f k8s/. It works, and it has three quiet problems. The CI system holds credentials that can change anything in the production cluster, so anyone who can edit a workflow file can too. When someone runs kubectl edit during an incident, the cluster no longer matches the repository and nothing notices. And “what was running at 14:00 yesterday?” means reading CI logs.

Every tool in this group, Kubernetes, Terraform and Kustomize, is declarative. GitOps finishes the job. The declaration lives in Git, and a controller makes reality match it, all the time.

The principles

The OpenGitOps project, a CNCF working group, condenses the idea into four principles:

  1. Declarative. The desired state is described, not scripted.
  2. Versioned and immutable. It is stored in a system like Git that keeps full history.
  3. Pulled automatically. Agents fetch the desired state themselves.
  4. Continuously reconciled. Agents keep comparing actual with desired state and correcting it.

The third is the big change from a normal pipeline. Instead of CI pushing into the cluster, an agent inside the cluster pulls from Git. CI builds and tests the image, then commits the new tag or digest to a config repository. That is all it is allowed to do.

The loop, small enough to watch

I built a toy GitOps agent in Python to watch the cycle with real Git. A config repository holds one file, notes-api.json, with the image and replica count. A “cluster” is a JSON file. The agent reads the file at Git HEAD, compares it with the cluster, applies the difference and reports the commit it synced to. Every command here ran on this Mac:

$ python3 sync.py
  image: None -> notes-api:1.4.2
  replicas: None -> 3
synced to 059f961
$ python3 sync.py   # after merging the 1.5.0 commit
  image: notes-api:1.4.2 -> notes-api:1.5.0
synced to 5c67c75
$ python3 sync.py   # after someone scaled the live app to 1 by hand
  replicas: 1 -> 3
synced to 5c67c75
$ python3 sync.py
in sync with 5c67c75
$ python3 sync.py   # after git revert of the release
  image: notes-api:1.5.0 -> notes-api:1.4.2
synced to 2b3f66a
$ git log --oneline
2b3f66a Revert "Release notes-api 1.5.0"
5c67c75 Release notes-api 1.5.0
059f961 Deploy notes-api 1.4.2

Three things to notice. A release is a commit. The hand-made change to the live system was undone on the next pass, because Git did not say 1 replica. And the rollback was git revert, which left a record of who rolled back and when. The real agents run this loop every few minutes and on Git webhooks, against every object in the cluster.

Argo CD

Argo CD runs in the cluster and watches Application objects. Each one says “make this destination match this path in this repository”. From the Argo CD docs, not run here, since I had no cluster:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: notes-api-prod
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/acme/notes-config.git
    targetRevision: main
    path: overlays/prod
  destination:
    server: https://kubernetes.default.svc
    namespace: prod
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

path points at a Kustomize overlay, and Argo CD renders it, or a Helm chart, itself. selfHeal turns on the drift reversal you saw above. prune deletes resources that were removed from Git. Without it they keep running, orphaned. Argo CD’s web UI shows each application’s resource tree, its sync status and a diff against Git, which is a large part of why teams choose it.

Flux

Flux splits the same job across small controllers. A GitRepository object says where to fetch from, and a Kustomization object (Flux’s own kind, distinct from Kustomize’s file) says what path to apply and how often:

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: notes-api-prod
  namespace: flux-system
spec:
  interval: 5m
  sourceRef:
    kind: GitRepository
    name: notes-config
  path: ./overlays/prod
  prune: true

Flux is driven mainly from its CLI and from Git, with the UI as an add-on rather than the centre, and it has a HelmRelease kind for charts and controllers that can commit new image tags for you. The latest releases when I checked GitHub were Argo CD v3.6.3 and Flux v2.10.1. Either one does the core loop well. Pick Argo CD if a shared UI for many teams matters, and Flux if you prefer everything as Kubernetes objects.

Practical notes

  • Keep config apart from code. A separate config repository, or at least a separate path, stops every code commit from triggering a sync, and lets production changes carry their own review rules.
  • Secrets cannot go in Git as plain text. Use encrypted files (SOPS, Sealed Secrets) or have the cluster fetch them from a secret store, covered in secrets management for infrastructure.
  • It is continuous deployment by commit. Merging to the production path is the deploy, so put the human approval, if you want one, on that merge. That is the delivery versus deployment choice made in Git.

About the video

“GitOps CRASH COURSE For Beginners | ArgoCD & FluxCD” is from Vishakha Sadhwani, published July 2026, 10 minutes 23 seconds. Its chapters cover what GitOps is, CI/CD versus GitOps, a GitOps setup on Kubernetes, Argo CD setup, Flux setup, Argo CD versus Flux, benefits, and scenario-based interview questions. Its description also mentions reconciliation loops, drift detection and rollback. English was judged from the title, description, channel and its English auto-caption track. Another of this creator’s videos had a Hindi auto-caption track, so I checked this one’s specifically. Nana’s 2021 video in deeper explains push versus pull clearly, without tool setup.

Where this fits

This closes infrastructure as code: servers, images, clusters and the apps on them all come from files in Git. The next group covers what those files usually point at, starting with cloud service models.

Check yourself

  1. 01In a push-based pipeline CI runs kubectl apply. What changes about credentials in a GitOps pull model?

    The cluster's own agent fetches from Git and applies changes, so CI never holds cluster-admin credentials. CI only needs permission to push a commit to the config repository.

  2. 02During an incident someone scales a Deployment by hand with kubectl. What does a GitOps agent with self-heal do?

    It sees the live replica count differs from Git and sets it back. To keep the change, it must be committed to Git.

  3. 03How do you roll back a bad release under GitOps?

    Revert the commit that changed the version in the config repository. The agent syncs the reverted state like any other change.

  4. 04What does prune mean in Argo CD's automated sync?

    Resources that exist in the cluster but have been removed from Git are deleted. Without prune they are left running, unmanaged.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark