GitOps Basics: Managing Infrastructure Through Git

GitOps uses Git as the single source of truth for both application and infrastructure configuration, with automated processes reconciling actual state to match what's declared in Git. This guide covers the core concepts and a practical starting approach.

The Core GitOps Principle

Rather than manually applying changes to infrastructure (running commands directly against production), you commit your desired state to Git, and an automated process ensures the actual running system matches that declared state — Git becomes the audit trail and single source of truth for "what should be running."

How GitOps Differs from Traditional CI/CD

Traditional CI/CD typically pushes changes (a pipeline runs and directly applies changes to servers); GitOps typically pulls — an agent running in your infrastructure continuously checks Git for the desired state and reconciles any drift, rather than an external process pushing changes in.

Building Blocks for a Simple GitOps Approach

See Infrastructure as Code Basics: Managing VPS Config with Terraform and How to Version Control Your Server Configuration — version-controlling your infrastructure configuration is the foundational prerequisite; GitOps adds the automated reconciliation layer on top.

A Simple GitOps Pattern Without Kubernetes

#!/bin/bash
# Runs periodically via cron/systemd timer
cd /opt/infra-config
git pull
ansible-playbook site.yml

A basic GitOps-style pattern: periodically pulling the latest committed configuration and applying it — simpler than full GitOps tooling, but captures the core "Git as source of truth, automated reconciliation" principle.

GitOps for Kubernetes (Where It's Most Commonly Used)

Dedicated GitOps tools designed specifically for Kubernetes continuously monitor a Git repository containing Kubernetes manifests, automatically applying any changes and correcting drift — the most mature and common context where "GitOps" as a formal practice is applied, given Kubernetes' inherently declarative resource model.

Benefits of the GitOps Approach

  • Complete audit trail — every infrastructure change has a corresponding Git commit with author, timestamp, and reasoning
  • Easy rollback — reverting infrastructure is as simple as reverting the relevant Git commit
  • Drift detection — the reconciliation process naturally surfaces any manual, out-of-band changes that diverge from the declared state

Handling Secrets in a GitOps Workflow

See How to Manage Secrets in a CI/CD Pipeline — secrets genuinely shouldn't be committed directly to Git even in a GitOps model; use a proper secrets manager referenced by your configuration, or specialized encrypted-secrets-in-Git tooling designed for this specific GitOps challenge.

Starting Simple

Full GitOps tooling (particularly Kubernetes-specific tools) may be more machinery than a smaller VPS-based setup genuinely needs — the core principle (version-controlled infrastructure config, automated/consistent application of that config) can be adopted incrementally without necessarily needing dedicated GitOps platform tooling for a simpler setup.

When GitOps Formal Tooling Makes Sense

As your infrastructure grows more complex (particularly with Kubernetes, or managing many environments), dedicated GitOps tooling's more sophisticated drift detection, reconciliation, and multi-environment management genuinely earns its additional complexity.

Continue Reading

Browse more articles in DevOps & CI/CD.

  • gitops basics explained, git as source of truth infrastructure, gitops without kubernetes, infrastructure reconciliation
  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Articles connexes

How to Set Up a Self-Hosted GitHub Actions Runner on a VPS

GitHub Actions' hosted runners work well for most projects, but a self-hosted runner on your own...

How to Deploy Automatically on Git Push (Webhook-Based Deployment)

Automating deployment whenever you push to a specific branch removes the manual "SSH in and pull"...

How to Set Up Blue-Green Deployment on a VPS

Blue-green deployment runs two identical production environments — only one live at a time...

How to Use Ansible for Server Configuration Management

Ansible automates server configuration through simple, human-readable YAML files — letting...

Infrastructure as Code Basics: Managing VPS Config with Terraform

Terraform lets you define infrastructure (VPS instances, networks, DNS records) as code, applied...