Lesson 14 GitOps with ArgoCD
Theme:
Lesson 14 · Slide 1

Lesson 14 — GitOps with ArgoCD

Stop running helm upgrade by hand. Git push is the only deploy. Drift detection is automatic.

Cloud Infra & DevOps Module 5 ArgoCD GitOps App-of-Apps
Lesson 14 · Slide 2

The L11–L13 workflow (the one we’re replacing)

What we’ve been doing

Developer edits code → push → CI builds image → push image → SSH or kubectl context → helm upgrade --set image.tag=NEW

The problem

Many of those steps are human, with admin perms on the cluster.

“This is not ‘deploying’. This is ‘a human deploying’. They are different problems.”
Lesson 14 · Slide 3

GitOps in one paragraph

GitOps = git is the desired state; a controller in the cluster watches git and makes the cluster match.

Lesson 14 · Slide 4

ArgoCD’s Application CR

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: url-shortener, namespace: argocd }
spec:
  source:
    repoURL: https://github.com/me/url-shortener
    path: cloud-devops/sample-app/helm
    targetRevision: main
    helm:
      valueFiles: [values-prod.yaml]
  destination:
    server: https://kubernetes.default.svc
    namespace: url-shortener
  syncPolicy:
    automated: { prune: true, selfHeal: true }

A kind: Application is the contract — “here’s a git location and a target cluster, keep them in sync”.

Lesson 14 · Slide 5

automated.selfHeal — the drift bit

With selfHeal: true, ArgoCD reconciles every 3 min (configurable). If a human kubectl edits the Deployment to bump replicas to 99, ArgoCD reverts it within 3 min back to what git says.

This is the deal: lose kubectl edit access; gain a controller that does it for you, with an audit trail.

The HPA gotcha: if HPA scales replicas from 3 to 8 and ArgoCD owns spec.replicas, ArgoCD reverts to 3 immediately. Fix covered on the next slide.
Lesson 14 · Slide 6

HPA + GitOps: the ignoreDifferences rule

spec:
  ignoreDifferences:
  - group: apps
    kind: Deployment
    jsonPointers:
    - /spec/replicas

Tells ArgoCD “the HPA owns replicas; don’t reconcile that field”.

Without this, every HPA scale-up is followed by an ArgoCD revert 3 min later. With it, HPA and ArgoCD coexist cleanly.
Lesson 14 · Slide 7

App-of-Apps

One root Application whose source is a directory full of other Application manifests. Result: one git push that creates 10 child Applications.

Standard pattern for “cluster bootstrap” — a single command brings ingress, cert-manager, monitoring, the app, all in the right order via sync waves.

The root Application watches a directory. Add a new child by adding a new YAML file in that directory and pushing. ArgoCD discovers it automatically.
Lesson 14 · Slide 8

Sync waves

metadata:
  annotations:
    argocd.argoproj.io/sync-wave: "-1"   # before others

ArgoCD applies manifests in ascending sync-wave order:

Inside a wave, parallel. Across waves, serial — ArgoCD waits for the previous wave to be Healthy before advancing.

Lesson 14 · Slide 9

ApplicationSet for dev/stage/prod

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
spec:
  generators:
  - list:
      elements:
      - { env: dev,   cluster: https://...dev,   valueFile: values-dev.yaml }
      - { env: stage, cluster: https://...stage, valueFile: values-stage.yaml }
      - { env: prod,  cluster: https://...prod,  valueFile: values-prod.yaml }
  template:
    metadata: { name: 'url-shortener-{{env}}' }
    spec:
      source: { ... helm: { valueFiles: ['{{valueFile}}'] } }
      destination: { server: '{{cluster}}', namespace: url-shortener }

One template, three rendered Applications. Adding a qa environment is a 4-line YAML change.

Lesson 14 · Slide 10

The “deploy” workflow under ArgoCD

  1. Developer pushes code → CI builds image, pushes to GHCR.
  2. Bot (or human) updates values-prod.yaml to point at the new image tag, opens a PR.
  3. PR review + merge.
  4. ArgoCD sees the change within 3 min, syncs, rolls out.
  5. Developer watches in ArgoCD UI / Grafana, never touches the cluster.
No kubectl, no helm, no SSH.
Lesson 14 · Slide 11

Drift detection in practice

Open ArgoCD UI → click url-shortener → see the resource tree. Anything OutOfSync is shown in yellow. Click → “Diff” → shows desired vs live side-by-side.

Either way, drift is a 30-second look, not a quarterly audit.

Lesson 14 · Slide 12

The L14 diff

sample-app/argocd/
  install.yaml             # ArgoCD itself; one-time install
  app-url-shortener.yaml   # the Application
  app-of-apps.yaml         # the root Application
  appset-environments.yaml # ApplicationSet for dev/stage/prod
  children/                # individual Application manifests for
                           # cert-manager, ingress-nginx, prometheus, the app
Lesson 14 · Slide 13

What we’re not doing (yet)

Lesson 14 · Slide 14

Recap & what’s next

This is the last lesson. You have built a path-of-a-feature deployment stack: container → CI → registry → Kubernetes → ingress → observability → autoscale → GitOps. The sibling Data Engineering with Python course is the natural next track — it applies the same container/CI/K8s foundations to data pipelines, Spark, and orchestration. Ship one of your own.