GitOps: Workflow, Components, and Tradeoffs

What is GitOps?

Modern cloud-native applications are built for speed and scale—mature DevOps teams deploy application code dozens or hundreds of times per day using version control, code review, and CI/CD pipelines. Yet infrastructure operations often lagged behind as manual work by specialized teams.

GitOps (Git + Operations) is an operational framework that applies DevOps best practices—version control, collaboration, compliance, and CI/CD—directly to infrastructure automation. Just as application source code deterministically compiles into identical binaries, GitOps stores infrastructure definitions as Infrastructure as Code (IaC) files in Git so that deploying those files generates the exact same environment every time:

“Config files” : “Infrastructure” = “App Source Code” : “App binaries” (PDF p. 27 / printed slide 27)

The four components and end-to-end workflow

A GitOps workflow relies on four key components (PDF p. 28 / printed slide 28):

  1. Git repository: The single source of truth describing the entire desired state of both infrastructure and applications.
  2. CD pipeline: Builds, tests, and prepares configuration updates.
  3. Deployment tool (GitOps tool): Watches the Git repository and automatically applies changes from Git to the target environment.
  4. Monitoring system: Tracks live infrastructure health and feeds observations back to the team—often tying back into Git so fixes are committed and auto-applied.

Full-cycle trace (PDF p. 29 / printed slide 29)

  1. A developer updates App Code and pushes to the application Git repository.
  2. The Build (CI) pipeline tests the code, builds a container image, pushes it to the Image Repo, and triggers a Config Update (e.g., bumping the image tag) in the infrastructure/app-infra Git repository.
  3. The GitOps Tool continuously compares the Git repository against Cluster One and Cluster Two, automatically reconciling any difference until the live clusters match Git.
App Code ──▶ Git ──▶ Build ──▶ Image Repo
                       │
                 Config Update
                       ▼
Infra / App Defs ◀──▶ Git (Source of Truth) ◀──▶ GitOps Tool ◀──▶ Cluster One & Cluster Two
  • ArgoCD demonstration outline (PDF p. 30 / printed slide 30):
    1. Place a Kubernetes Deployment manifest in a GitHub repository.
    2. Apply an ArgoCD Custom Resource (CR) instructing ArgoCD to synchronize the cluster with that GitHub repo (for CRDs and Kubernetes controllers, see Kubernetes Principles Controllers and Resource Model).
    3. ArgoCD automatically configures the Deployment on the cluster.
    4. Edit replicas in the GitHub file and commit → ArgoCD detects the diff and reflects the new replica count on the cluster automatically.

Added practical clarification: environment variables and secret keys

In a Kubernetes + GitOps cycle, normal non-sensitive environment variables (such as LOG_LEVEL=debug) are written directly inside the pod spec’s env: block in Git; ArgoCD forwards the updated YAML to the Kubernetes API, which starts new containers with that environment variable injected.

Secret keys (API tokens, database passwords, private keys) must never be committed in plaintext to Git, because anyone with read access to the repo—or an attacker who compromises it—would gain those credentials (see Slide 34’s security warning below). Three standard industry patterns (practical addition outside the slides) solve this:

PatternWhat lives in Git?How the secret reaches the VM/containerBest suited for
1. Secret Manager (e.g., Vault, AWS/GCP Secrets Manager)Only the secret’s name/pathThe VM or cluster controller authenticates via machine identity (IAM) and fetches the real value at runtime into memory/envProduction cloud & Kubernetes (easy secret rotation)
2. Encrypted Secrets in Git (e.g., Sealed Secrets, Mozilla SOPS)Ciphertext encrypted with a public keyOnly the live cluster holds the private decryption key and decrypts it before injecting into the containerPure GitOps workflows wanting every artifact versioned in Git
3. CI/CD Secrets (e.g., GitHub/GitLab CI variables)A variable placeholder (e.g., var.api_key)The CI runner injects the secret during tofu apply or ansible-playbook over SSH (watch out: encrypt Terraform state files so secrets do not leak there)Smaller setups and VM-based Terraform/Ansible pipelines

Pros and cons of GitOps

Pros (PDF pp. 31–32 / printed slides 31–32)Cons / risks (PDF pp. 33–34 / printed slides 33–34)
1. Version control for everything: Full change history and easy rollback via Git.1. Initial setup complexity: High upfront effort to codify existing manual systems and pipelines.
2. Improved collaboration & transparency: Pull requests let teammates review, comment, and approve infra changes.2. Learning curve: Steep for teams unfamiliar with IaC or Git workflows.
3. Consistency & standardization: Declarative configs produce repeatable environments across dev/stag/prod.3. Overhead for small changes: Even trivial tweaks must pass through commits/PRs.
4. Automated deployment & rollback: Reduces manual steps and human error.4. Dependency on Git and CI/CD tooling: Outages in Git or pipeline tools directly block operations.
5. Enhanced security & compliance: Easier policy enforcement and built-in Git audit trail.5. Potential for configuration drift: Manual edits made directly in the live environment break parity with Git.
6. Seamless infrastructure modification: Updating infra is as simple as editing code.6. Security concentration: Compromising the Git repository puts the entire infrastructure at risk.
7. Natural CI/CD fit: Unifies commit-to-deployment pipelines.7. Scale and complexity challenges: Large, multi-cluster estates become harder to structure cleanly in Git.

Common confusion: Configuration Drift vs. GitOps reconciliation

Configuration drift happens when someone bypasses Git and modifies a live cluster or VM directly (e.g., running kubectl edit during an incident). Without GitOps enforcement, that ad-hoc change stays invisible in Git and future deploys fail unpredictably; with an active GitOps controller, either the controller overwrites the manual hotfix back to Git’s state or flags the cluster as OutOfSync.

Retrieval

  1. Explain the analogy "Config files" : "Infrastructure" = "App Source Code" : "App binaries" from Slide 27.
    Just as compiling the same application source code deterministically produces the same executable binary, applying the same GitOps configuration files produces the exact same infrastructure environment every time—eliminating manual “snowflake” servers.
  2. During an outage, an engineer logs directly into a Kubernetes cluster and scales a deployment manually without touching Git. Which risk from Slide 34 did they create, and why does it undermine GitOps?
    They introduced configuration drift. Git is no longer the accurate single source of truth for what is running in production; either the change is lost when the GitOps tool reconciles back to Git, or live environments diverge silently from reviewed configuration history.
  3. Why does committing an unencrypted database password to a GitOps repository violate Slide 34’s security warning, and how does a Secret Manager pattern avoid this?
    Because Git controls the entire infrastructure, compromising the Git repository exposes every credential stored in it. Using a Secret Manager keeps only a non-sensitive secret path/name in Git while letting the runtime cluster or VM authenticate directly to the vault to fetch the actual secret.

Source: Lecture 14 - DevOps and GitOps, PDF pages 24–34 (printed slides 24–34).