DevOps · Guide

GitOps & Argo CD

The cluster pulls its desired state from git, and anything that drifts gets corrected.

— min read DevOps

Git As The Source Of Truth

GitOps is one idea: the desired state of a system lives in git, and an agent inside the cluster continuously reconciles reality against it. Deployment becomes a commit, and rollback becomes a revert.
PrincipleIn practice
DeclarativeThe whole system described as data, not as steps
VersionedEvery change is a commit with an author and a diff
Pulled automaticallyAn in-cluster agent applies, rather than CI pushing
Continuously reconciledManual changes are reverted, not merely detected

The audit trail comes free: what is running is whatever the repository says, and git log is the deployment history — including who approved it.

Push Versus Pull

Traditional CI/CD pushes: the pipeline holds cluster credentials and runs kubectl apply. GitOps pulls: an agent in the cluster watches the repository and applies changes itself.

Push (CI applies)Pull (agent reconciles)
CredentialsCI holds cluster adminNothing outside needs cluster access
DriftDetected at bestCorrected automatically
NetworkCI must reach the clusterCluster reaches out — no inbound path
State of truthWhatever ran lastThe repository, always
The security argument is the strongest one: with pull, a compromised CI system cannot deploy to production, because CI never had credentials to the cluster in the first place.

Argo CD & Repository Layout

Argo CD and Flux both watch repositories and reconcile. An Argo Application ties a source path to a destination cluster and namespace.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: orders-prod, namespace: argocd }
spec:
  source:
    repoURL: https://github.com/acme/deploy
    path: envs/prod/orders          # rendered manifests, not templates
    targetRevision: main
  destination: { server: https://kubernetes.default.svc, namespace: orders }
  syncPolicy:
    automated: { prune: true, selfHeal: true }   # correct drift, remove orphans
ConventionWhy
Application code and deploy config in separate reposA config change should not rebuild the image
A directory per environmentDiffs between environments are visible
Images pinned by digest:latest makes the repo a lie
prune: trueDeleting a file actually removes the resource
selfHeal: trueConsole edits are reverted within a cycle
Secrets cannot be committed in plaintext. Use sealed secrets, SOPS with a KMS key, or an external secrets operator that pulls from a real secret manager — the repository is readable by everyone who can read the repository.

Promotion & Progressive Delivery

Promotion becomes a pull request: the image digest that passed in staging is proposed for production, reviewed and merged. There is no separate deploy button, and no way to ship something that is not in the repository.

StepArtefact
CI builds and testsAn image, tagged by digest
Automation updates stagingA commit to the staging path
Agent reconcilesStaging now runs it
PromotionA pull request into the production path
RollbackRevert the commit

Controllers like Argo Rollouts add canary and blue-green on top, shifting traffic gradually and rolling back automatically when metrics degrade — the subject of the release strategies lesson.

Interview Questions

What is GitOps?

Desired state declared in git, with an in-cluster agent continuously reconciling reality against it. Deployment is a commit and rollback is a revert.

Why is pull safer than push?

CI never holds cluster credentials and needs no inbound network path. A compromised pipeline cannot deploy to production because it was never able to reach it.

What does self-heal do?

It reverts changes made outside git within a reconcile cycle, so manual console edits are corrected rather than merely reported as drift.

Why separate application and deploy repositories?

A configuration change should not trigger an image rebuild, and the deploy repository has a different review audience and change cadence.

How are secrets handled?

Never in plaintext. Sealed secrets, SOPS with a KMS key, or an external secrets operator that fetches from a real secret manager at reconcile time.

Why pin images by digest?

A moving tag means the repository no longer describes what is running, which removes the entire guarantee GitOps exists to provide.

Quick Quiz

1. In GitOps the source of truth is…
2. Pull-based deployment means…
3. selfHeal corrects…
4. Using :latest in a GitOps repo…
5. Rollback in GitOps is…