GitOps Module — Presentation 1 of 4

GitOps Fundamentals

From Traditional Deployments to Git-Driven Operations

Civica Training Program

The Journey Begins

Your team has decided to adopt GitOps. Here's the journey from zero to production...

The Scenario

Your team manages 12 microservices across dev, staging, and production on AKS. Deployments are manual, error-prone, and nobody knows what's actually running in production. Last week, a rogue kubectl apply brought down the payment service for 45 minutes.

The Question

How do we make deployments repeatable, auditable, and recoverable? How do we make the cluster's state as trustworthy as our codebase?

The answer: GitOps.

What Is GitOps?

GitOps is an operational framework that applies DevOps best practices for infrastructure automation using Git as the single source of truth.

The Definition

GitOps uses Git repositories as the source of truth for defining the desired state of infrastructure and applications. An automated process ensures the actual state matches the desired state declared in Git.

Coined By

The term "GitOps" was coined by Weaveworks in 2017. It evolved from their experience running Kubernetes in production and wanting to apply Git workflows to operations.

Now an industry-standard practice endorsed by the CNCF.

"If it's not in Git, it doesn't exist. If it's in Git, it should be running."

The Four Principles of GitOps

Defined by the OpenGitOps project (CNCF Sandbox).

1. Declarative

A system managed by GitOps must have its desired state expressed declaratively. You describe what you want, not how to get there.

2. Versioned and Immutable

Desired state is stored in a way that enforces immutability, versioning, and a complete history. Git provides this naturally.

3. Pulled Automatically

Software agents automatically pull the desired state declarations from the source. No manual pushes required.

4. Continuously Reconciled

Software agents continuously observe actual system state and attempt to apply the desired state. Drift is detected and corrected.

Why GitOps? The Benefits

GitOps brings software engineering practices to infrastructure management.

100%
Audit Trail

Every change is a Git commit with author, timestamp, and message. Compliance built in.

Fast
Rollback

Revert a deployment with git revert. The agent reconciles automatically.

Self
Healing

If someone manually changes the cluster, the agent detects drift and corrects it.

Security

Cluster credentials stay in the cluster. No CI/CD pipeline needs direct cluster access.

Consistency

All environments are managed identically. Same process for dev, staging, and prod.

Productivity

Developers use familiar Git workflows: PRs, reviews, and merges to deploy.

Traditional CI/CD vs GitOps

Understanding where GitOps diverges from traditional deployment pipelines.

AspectTraditional CI/CDGitOps
Deployment triggerPipeline pushes to clusterAgent pulls from Git
Source of truthCI/CD pipeline configGit repository
Cluster accessCI needs kubeconfig / credentialsAgent runs inside cluster
Drift detectionNone (fire-and-forget)Continuous reconciliation
RollbackRe-run old pipeline or manualgit revert
Audit trailPipeline logs (often ephemeral)Git history (permanent)
Multi-clusterComplex pipeline branchingOne repo per cluster / overlay

Knowledge Check #1

Test your understanding of GitOps fundamentals.

Q1: Which of the following is NOT one of the four GitOps principles?

Answer: C) Imperatively Executed. GitOps principles are: Declarative, Versioned and Immutable, Pulled Automatically, and Continuously Reconciled. Imperative execution is the opposite of the GitOps approach.

Q2: Who coined the term "GitOps"?

Answer: B) Weaveworks. Weaveworks coined the term "GitOps" in 2017 based on their experience running Kubernetes in production.

Q3: In GitOps, how does the cluster get updated?

Answer: B) An agent inside the cluster pulls the desired state from Git. This is the pull-based model, where a GitOps agent (like ArgoCD) running inside the cluster continuously reconciles the actual state with the desired state in Git.

Git as the Single Source of Truth

The story of how a simple idea transformed operations.

The "Before" World

  • Manifests scattered across laptops, CI servers, and wikis
  • "What's running in production?" requires logging into the cluster
  • Hotfixes applied directly with kubectl edit and never tracked
  • New team members have no idea what's deployed or why

The "After" World with GitOps

  • One Git repo describes everything running in each environment
  • git log tells you who changed what, when, and why
  • Pull requests provide code review for infrastructure changes
  • New team member? git clone and they see the entire system

A Day in the Life: The Git Commit Story

Following a change from developer intent to production reality.

1. Developer creates a branch and updates image tag in deployment.yaml
2. Opens Pull Request — team reviews the change
3. PR is approved and merged to main branch
4. GitOps agent detects the new commit in Git
5. Agent compares Git state vs cluster state — finds drift
6. Agent applies the change to the cluster automatically
7. Cluster matches desired state — deployment complete!

Push vs Pull Model

Two fundamentally different approaches to deploying changes.

Push Model (Traditional CI/CD)

  • CI/CD pipeline runs kubectl apply or helm upgrade
  • Pipeline needs cluster credentials
  • Deployment is a point-in-time event
  • No ongoing verification after deployment
  • Drift can happen silently

Risk: If someone runs kubectl edit in production, the pipeline doesn't know or care.

Pull Model (GitOps)

  • Agent inside the cluster polls Git for changes
  • No external system needs cluster credentials
  • Deployment is continuous reconciliation
  • Agent constantly verifies actual vs desired state
  • Drift is detected and auto-corrected

Benefit: The cluster heals itself. Git is always the authority.

Push vs Pull: Visual Comparison

Seeing the architectural difference.

Push Model

Developer pushes code
CI builds & tests
CI/CD pushes to cluster (needs credentials!)
Kubernetes Cluster

Pull Model (GitOps)

Developer pushes code
CI builds & pushes image, updates Git repo
Git Repo (source of truth)
↑ pulls
Agent inside cluster pulls from Git

The GitOps Workflow: Commit to Cluster

A four-phase continuous loop.

1

Commit

Developer merges a change to the GitOps repo. This could be a new image tag, a config change, or a new resource.

2

Detect

The GitOps agent detects the new commit by polling the repository (typically every 3 minutes) or via a webhook.

3

Sync

The agent compares Git state with cluster state. If there's a difference, it applies the changes to the cluster.

4

Verify

The agent verifies the resources are healthy (pods running, services available). Reports status back to the UI.

This loop runs continuously. It's not a one-time deployment — it's ongoing reconciliation.

Drift Detection: The Self-Healing Cluster

What happens when someone makes a manual change?

Scenario: The Midnight Hotfix

It's 2 AM. An on-call engineer directly scales a deployment from 3 to 5 replicas using kubectl scale to handle a traffic spike. They forget to update the Git repo.

Without GitOps

  • The change persists until someone notices
  • Git repo says 3 replicas, cluster has 5
  • Next deployment resets it to 3 — surprise!
  • No record of why it was changed

With GitOps

  • Agent detects drift: cluster (5) vs Git (3)
  • Agent reverts to 3 replicas (Git wins)
  • Team gets a notification about the drift
  • Proper fix: update Git to 5 replicas via PR

Knowledge Check #2

Push vs Pull models and GitOps workflow.

Q1: What is the key security advantage of the pull model over the push model?

Answer: B) No external system needs cluster credentials. In the pull model, the GitOps agent runs inside the cluster and pulls from Git. CI/CD pipelines never need kubeconfig or service account tokens for the production cluster.

Q2: What are the four phases of the GitOps workflow?

Answer: B) Commit, Detect, Sync, Verify. The GitOps loop: a commit is made to Git, the agent detects the change, syncs the cluster to match, and verifies the resources are healthy.

Q3: When drift is detected in a GitOps system, what happens?

Answer: C) The agent reconciles the cluster to match Git. Git is the source of truth. When drift is detected, the agent applies the desired state from Git to the cluster, correcting any manual changes.

GitOps Tools Landscape

The ecosystem of tools that implement GitOps principles.

ArgoCD

  • CNCF graduated project
  • Rich Web UI and CLI
  • Supports Helm, Kustomize, Jsonnet, plain YAML
  • Application-centric approach
  • Strong RBAC and SSO integration
  • 10,000+ GitHub stars

Flux CD

  • CNCF graduated project
  • CLI-first, no built-in UI
  • Supports Helm, Kustomize, plain YAML
  • Git-repository-centric approach
  • Tightly integrated with Kubernetes APIs
  • Deep integration with Flagger for canaries

Jenkins X

CI/CD + GitOps for Kubernetes. Opinionated, full-stack platform.

Rancher Fleet

GitOps at scale for multi-cluster management.

Codefresh

Enterprise GitOps with built-in CI and ArgoCD integration.

ArgoCD vs Flux: Head to Head

Both are CNCF graduated — choosing between them depends on your needs.

FeatureArgoCDFlux CD
Web UIRich, built-in UIThird-party (Weave GitOps)
CLIFull-featured CLIFull-featured CLI
Multi-tenancyProjects with RBACNamespace-scoped controllers
TemplatingHelm, Kustomize, JsonnetHelm, Kustomize
SSOBuilt-in OIDC/SAMLNo built-in auth
Progressive deliveryArgo Rollouts (separate)Flagger (integrated)
ArchitectureCentralised controllerDistributed controllers
Learning curveModerate (UI helps)Steeper (CLI-only)

Why ArgoCD for Our Stack?

Making the right choice for Civica's AKS-based platform.

Azure AD Integration

ArgoCD's built-in OIDC support integrates natively with Azure AD for SSO. Map Azure AD groups to ArgoCD RBAC roles — no extra tools needed.

Visual Operations

The ArgoCD UI provides real-time application topology, sync status, and health. Non-CLI users (managers, auditors) can see what's deployed.

Multi-Team Support

ArgoCD Projects allow team isolation. Each team sees only their applications. RBAC controls who can sync, override, or delete.

Ecosystem

Argo Rollouts for canary/blue-green deployments, Argo Events for event-driven workflows, and a massive community with extensive documentation.

Repository Strategy: Separation of Concerns

A critical decision: how do you organise your Git repositories?

Key Principle: Separate Application Code from Configuration

Your application source code (Go, Java, .NET) and your Kubernetes manifests should live in separate repositories. This separation allows independent versioning, different access controls, and cleaner Git histories.

Application Repo

app-service/
  src/
  tests/
  Dockerfile
  .github/workflows/ci.yaml

Contains source code, Dockerfile, and CI pipeline. Outputs a container image.

GitOps Repo

gitops-config/
  apps/
    app-service/
      base/
      overlays/
        dev/
        staging/
        prod/

Contains Kubernetes manifests. ArgoCD watches this repo.

Mono-Repo vs Multi-Repo

Two strategies for organising your GitOps configuration.

Mono-Repo

All application configs in a single repository.

gitops-config/
  apps/
    service-a/
    service-b/
    service-c/
  infra/
    cert-manager/
    ingress-nginx/
  • Simple to manage and discover
  • Single PR can update multiple apps
  • Harder to restrict access per team
  • Git history can get noisy

Multi-Repo

Each team or application owns its own config repo.

team-payments-config/
  payment-api/
  payment-worker/

team-platform-config/
  cert-manager/
  ingress-nginx/
  • Strong ownership boundaries
  • Fine-grained access control
  • More repos to manage
  • Cross-cutting changes need multiple PRs

Recommended Repository Structure

A balanced approach that works well for most organisations.

gitops-config/
# Cluster infrastructure components
  infra/
    cert-manager/
    external-secrets/
    ingress-nginx/
    monitoring/

# Application deployments
  apps/
    payment-service/
      base/
        deployment.yaml
        service.yaml
        kustomization.yaml
      overlays/
        dev/
          kustomization.yaml
        staging/
          kustomization.yaml
        prod/
          kustomization.yaml
    order-service/
      base/
      overlays/

# ArgoCD application definitions
  argocd/
    apps.yaml          # App of Apps
    projects.yaml      # ArgoCD Projects

Knowledge Check #3

Repository strategies and tool choices.

Q1: Why should application source code and Kubernetes manifests be in separate repositories?

Answer: B) Independent versioning, access control, and cleaner history. Separating code from config allows each to evolve independently, have different access permissions, and maintain clean Git histories for auditing.

Q2: Which ArgoCD feature makes it particularly suited for enterprise teams?

Answer: C) Built-in OIDC/SSO and RBAC with Projects. ArgoCD natively supports OIDC (including Azure AD), SAML for SSO, and has a project-based RBAC model that enables multi-team isolation.

Q3: What is the primary disadvantage of a mono-repo approach for GitOps config?

Answer: B) Harder to restrict access per team. In a mono-repo, all teams have access to all configurations. Branch protection rules can help, but it's inherently harder to enforce team boundaries compared to separate repositories.

Environment Promotion with GitOps

How changes flow from dev to staging to production.

Dev Overlay
Staging Overlay
Prod Overlay
↑ ↑ ↑
Shared Base (deployment.yaml, service.yaml)

Strategy 1: Branch-per-Environment

Promote by merging dev branch into staging into prod. Simple but can lead to merge conflicts.

Strategy 2: Directory-per-Environment

Use Kustomize overlays in directories. Promote by updating the overlay. Recommended approach.

CI + GitOps: The Complete Picture

CI and GitOps are complementary, not competing.

Developer pushes code to App Repo
CI Pipeline: build, test, create container image
CI pushes image to Azure Container Registry
CI updates image tag in GitOps Repo (automated commit)
ArgoCD detects change in GitOps Repo
ArgoCD syncs cluster to match new desired state

CI handles building and testing. GitOps handles deploying and maintaining.

Image Update Automation

How the image tag update actually happens in the GitOps repo.

Option 1: CI Pipeline Updates Git

# GitHub Actions example
- name: Update image tag
  run: |
    cd gitops-config
    kustomize edit set image \
      myapp=myacr.azurecr.io/myapp:$TAG
    git commit -am "chore: bump myapp to $TAG"
    git push

Most common. CI has write access to the GitOps repo.

Option 2: ArgoCD Image Updater

# Annotation on ArgoCD Application
annotations:
  argocd-image-updater.argoproj.io/
    image-list: myapp=myacr.azurecr.io/myapp
  argocd-image-updater.argoproj.io/
    myapp.update-strategy: semver

ArgoCD watches the registry and auto-updates. Write-back to Git.

Rollback: Git Revert = Production Rollback

One of the most powerful benefits of GitOps.

The Scenario

You deployed version 2.3.0 of the payment service. It has a critical bug causing 500 errors. You need to roll back to 2.2.9 immediately.

Traditional Rollback

# Find the right version...
kubectl rollout undo deployment/payment
# Or re-run a pipeline...
# Or find the old Helm values...
# Hope nothing else changed...

Error-prone, stressful, and not audited.

GitOps Rollback

# One command:
git revert HEAD
git push

# ArgoCD auto-syncs
# Payment service is back to 2.2.9
# The revert is in Git history forever

Clean, audited, and stress-free.

GitOps Security Model

Reducing the attack surface of your deployment pipeline.

Principle of Least Privilege

  • CI pipelines: Only push images and update Git
  • Developers: Only access Git (PRs + reviews)
  • ArgoCD: Only reads Git and writes to its own cluster
  • Nobody: Has direct kubectl access in production

Credential Exposure

  • No kubeconfig in CI/CD environment variables
  • No service account tokens in pipeline logs
  • Git credentials are read-only deploy keys
  • Secrets managed via Sealed Secrets or External Secrets

With GitOps, the blast radius of a compromised CI pipeline is limited — it can't directly modify the cluster.

GitOps Challenges and Considerations

GitOps is powerful, but it's not magic. Be aware of these challenges.

Challenges

  • Secret management: Secrets can't go in Git as plain text
  • Stateful applications: Databases need special handling
  • Debugging: "Why didn't my change sync?" can be tricky
  • Learning curve: Teams need to learn Git workflows
  • Tooling overhead: ArgoCD itself needs to be managed

Solutions We'll Cover

  • Sealed Secrets / External Secrets for secret management
  • Operators for stateful workloads
  • ArgoCD UI + notifications for debugging
  • Training + documentation (this course!)
  • App of Apps for self-managing ArgoCD

What's Next: Your GitOps Journey

We've covered the "why" — now it's time for the "how".

Coming Up in This Module

  1. Presentation 2: Installing ArgoCD on AKS
  2. Presentation 3: Bootstrapping the GitOps Workflow
  3. Presentation 4: Azure Integration & Operations

Prerequisites to Prepare

  • Access to an AKS cluster (or minikube for local)
  • kubectl configured and working
  • helm CLI installed (v3+)
  • A Git repository you can write to
  • Azure CLI (az) authenticated

By the end of this module, you'll have a fully operational GitOps workflow deploying to AKS with ArgoCD.

Module 1 Summary

Key takeaways from GitOps Fundamentals.

Core Idea

Git is the single source of truth for your desired cluster state. An agent ensures reality matches that truth.

Four Principles

Declarative, Versioned & Immutable, Pulled Automatically, Continuously Reconciled.

Pull Model

The agent inside the cluster pulls state from Git. No external system needs cluster access.

ArgoCD

Our tool of choice: rich UI, RBAC, SSO, and excellent Kubernetes integration.

Separation

App code and K8s config live in separate repos. Kustomize overlays manage environments.

Security

Reduced attack surface. CI can't directly access clusters. Everything is audited in Git.

Questions & Discussion

GitOps Fundamentals

Next up: Installing ArgoCD on AKS

Civica Training Program GitOps Module — 1 of 4
1 / 30
← Back