Lesson 6 of 7 · Automation

GitOps

GitOps principles, push versus pull, Argo CD, Flux, and Git-driven Terraform, and how GitOps applies to databases.

Beginner 7 sections 4 min read

What GitOps is

GitOps is a way of running automation in which Git holds the desired state of your systems, and an automated agent keeps the real systems matching it. To change anything, you change Git through a reviewed pull request; the agent notices and applies it, and if anyone changes a system by hand, the agent puts it back.

The term was coined in 2017 by Weaveworks, for managing applications on Kubernetes, and the idea has since spread to infrastructure and databases. The OpenGitOps project, part of the Cloud Native Computing Foundation (CNCF), defines four principles:

1. Declarative
The desired state of the system is described declaratively, as files that say what should exist.
2. Versioned and immutable
That desired state is stored in Git, with a full history of every change.
3. Pulled automatically
Software agents pull the desired state from Git themselves, rather than a person or pipeline pushing it.
4. Continuously reconciled
The agents keep comparing the real state with the desired state, and correct any difference, called drift.

Push and pull

The key difference from an ordinary CI/CD pipeline is the direction:

PUSH: CI/CD PIPELINE GitPipelineTarget system merge triggerspushes once manual changes later go unnoticed PULL: GITOPS Git Agent Argo CD, Flux Target system pulls desired state compares and reconciles, again and again: drift is fixed
Push (CI/CD)Pull (GitOps)
Who applies changesA pipeline, triggered by a mergeAn agent running next to the system
How oftenOnce, when the pipeline runsContinuously, every few minutes
Manual changes (drift)Go unnoticed until something breaksDetected and reverted automatically
CredentialsThe pipeline needs access to every targetThe agent runs inside the target environment
RollbackRerun an older pipelineRevert the commit in Git; the agent does the rest

GitOps tools

Argo CD
The most widely used GitOps tool, for Kubernetes. It watches Git repositories, shows in a web dashboard whether each application is in sync, and applies changes automatically or with a click. It's a graduated CNCF project.
Flux
A lighter, command-line-focused GitOps tool for Kubernetes, also a graduated CNCF project.
GitOps for Terraform
Tools such as Atlantis, HCP Terraform (formerly Terraform Cloud), and Spacelift run terraform plan on every pull request and terraform apply on merge, and can detect drift on a schedule. It's not pure pull-based GitOps, but it brings the same Git-driven way of working to infrastructure.

GitOps and databases

Databases are a harder fit than applications, because they hold data that can't simply be recreated. GitOps works well for the parts of a database that are configuration:

  • Databases on Kubernetes are managed by operators, such as the Oracle Database Operator for Kubernetes or CloudNativePG for PostgreSQL. You describe the database in a YAML file in Git, such as its version, size, and replicas, and Argo CD or Flux keeps it that way.
  • Cloud databases are described in Terraform, run through Git-driven tools such as Atlantis, with drift checks.
  • Schema changes stay in Git as migrations, applied by Liquibase or Flyway, either by the pipeline or as a step the GitOps tool runs before the application updates.

What GitOps doesn't manage is the data itself. Backups, restores, and data fixes still need their own careful processes.

Why it matters for automation

  • Git becomes the control panel: every change, by anyone, goes through a reviewed pull request.
  • Drift disappears: systems stay exactly as the code describes.
  • The audit trail is automatic: Git's history is a record of every change to every system, and who approved it.
  • Recovery is simpler: rebuild an environment by pointing an agent at the same Git repository.

In practice: the change that undid itself

Kofi's team runs PostgreSQL on Kubernetes with an operator, managed by Argo CD from Git. During a busy afternoon, an engineer raises the database's memory limit directly in the cluster to work around a slowdown. Within minutes, Argo CD notices the cluster no longer matches Git and sets the limit back.

The slowdown returns, and the team learns two things. Argo CD did its job: the "quick fix" was drift. And the fix was real: the database did need more memory. So the change goes in properly, as a pull request to the YAML in Git, reviewed and merged, and Argo CD applies it. The team also agrees a rule for incidents: pause automatic sync for that database, fix it, then make the change in Git before resuming.

Key takeaways

  • GitOps keeps the desired state in Git, and agents continuously make the real systems match it.
  • Its four principles: declarative, versioned and immutable, pulled automatically, and continuously reconciled.
  • Unlike push-based pipelines, GitOps detects and fixes drift, and rollback is a Git revert.
  • Argo CD and Flux are the main GitOps tools for Kubernetes; Atlantis and HCP Terraform bring Git-driven workflows to Terraform.
  • For databases, GitOps manages configuration and schema; data still needs its own backup and recovery processes.