What is GitOps: The Beginner's Guide

Simply put, GitOps applies DevOps practices like version control and CI/CD to infrastructure management. The name GitOps, coined by Weavewerks, is from Git, an open-source version control system that allows teams to manage infrastructure using the same tools and orchestration processes they use for software development.

Speed and scalability drive the development of modern software applications, and mature DevOps organizations can deploy code to production hundreds of times a day. DevOps teams are able to do this through automation enabled by best practices such as version control, code review and CI/CD pipelines. But while the software development lifecycle (SDLC) has been largely automated, infrastructure management still relies on mostly manual processes and specialized teams. This makes it challenging to provision and configure cloud resources with the speed and scale continuous deployments require.

GitOps helps by automating the process of provisioning infrastructure. Rather than manually configuring an environment every time a new component is needed, GitOps teams use configuration files stored as code to automate the creation of environments using machine-readable definition files. These configuration files generate the same infrastructure each time they’re deployed, ensuring consistency across IT environments.

In this blog post we’ll look at how GitOps works, why you should use it and how you can apply it. We’ll also look at how to get started with GitOps along with some best practices to help set you up for success.

GitOps Basics

GitOps works by using a Git-based source code management system to build code-based infrastructure. It is an evolution of Infrastructure as Code (IaC), a DevOps practice used to provision and configure testing and deployment environments using scripts that are treated as part of the application’s code. The IaC process starts with a developer writing scripts that define the infrastructure configuration parameters. The scripts can be written using a declarative or imperative approach. Essentially, declarative programming lets the user say what infrastructure resources they want while imperative programming lets them say how they want the infrastructure resources created.

The declarative approach requires the user to “declare” what they want the infrastructure to look like by specifying a list of resources and the properties they should have. The IaC tool reads the script then installs and configures all the infrastructure components and manages the code version deployed to them. In the imperative approach, the user specifies a list of commands they want the IaC tool to run to provision the infrastructure step by step. The configuration scripts are sent to a code repository that supports version control, allowing the files to be easily reviewed, edited, copied and shared. When someone edits a file, merge requests and code review workflows validate the changes. Finally, the IaC platform follows the developer’s instructions to create and configure the infrastructure.

GitOps is essentially IaC using Git as the version control system for all infrastructure configurations. GitOps workflows consist of three primary components:

gitops-workflow-diagram

GitOps workflows consist of three components: IaC, merge requests and CI/CD.

Just like IaC, GitOps requires developers to declaratively describe the desired state of the system. The configuration files and source code are stored and version-controlled in a Git repository — a distributed version control system holding all of the app's code. This repository tracks every change made to files in that project over time and is the control system for creating, updating and deleting infrastructure components.

Merge requests are where code changes are implemented for all infrastructure updates. To roll out a new release, a developer makes a request to modify the state of the system in the Git repository (e.g. git repo). The alerted teams review and ultimately approve or reject the changes. If the changes are approved, a merge commits the code to the main branch and serves as an audit log.

When the changes are approved and merged, they are automatically applied to the live infrastructure. This lets developers continue using their normal GitOps pipeline for workflow and CI/CD practices.

When and why do you use GitOps?

GitOps makes the provisioning of infrastructure easier, faster and more scalable.

Conventional infrastructure management requires developers to file a ticket or email a request to the ITOps team whenever they want to provision infrastructure or cloud infrastructure resources. The ITOps team reviews and logs every request in a queue, then manually allocates the requested resources for each one by entering manual commands in a user interface. Although time consuming, this process worked well enough when most organizations had less infrastructure to manage and little turnover of components.

Today’s infrastructure is much more dynamic due to API-driven cloud environments that enable organizations to provision and decommission resources in seconds, rather than the long commitment required to deploy legacy infrastructure. Today, organizations may spin up thousands of development environments or microservices each week. It’s impractical to manage infrastructure manually; it would require submitting thousands of tickets every day to increase or decrease workload capacity as needed, plus a lot of time waiting for administrators to complete all those requests.

GitOps is a much more efficient solution. It replaces manual processes for provisioning and configuring infrastructure with automation. Developers can declare service-level objectives as part of their application code and have the infrastructure automatically scale to maintain these objectives. And it lets developers use familiar practices and manage infrastructure through the same version control system they use for application development. This means faster, more predictable deployments, more seamless code management and greater overall productivity.

GitOps Core Practices and Immutable Infrastructure

The three core practices of GitOps are:

  1. Declarative configuration: GitOps uses declarative description to define the desired state of the infrastructure or application in the target environment. The declarative description code is contained in a centralized Git repository or repo as a single source of truth for the whole system.
  2. The Git workflow: Everything is done by making changes to code or configuration files in Git. When a pull request is approved and merged, it automatically syncs the production environment to the new state of the repository.
  3. Separate configuration and deployment: Changes are applied to the target environment using a pull-based deployment. This keeps changes separate from the main project.

three-core-practices-of-gitops-diagram

The three core practices of GitOps include declarative configuration, the Git workflow and separate configuration and deployment.

The Role of Immutable Infrastructure

GitOps encourages developers to work with immutable infrastructures. Mutable and immutable are two different types of infrastructure environments. A mutable infrastructure can be modified after it has been provisioned — to accommodate a new virtual machine, for example. An immutable infrastructure cannot. Each type of environment has advantages and disadvantages.

Mutable infrastructure allows developers to customize existing servers to specific app or development needs rather than requiring them to establish new ones. This enables the infrastructure to meet the needs of each user, which is a significant advantage.

Immutable environments are more rigid. Infrastructure components are built to match particular specifications and once the infrastructure is provisioned, ad hoc modifications can’t be made. Any changes would require a whole new infrastructure to be built based on the new requirements. While there are many disadvantages to this system, immutable infrastructure eliminates configuration drift, makes it easier to identify and resolve technical issues, and ensures testing consistency from development through production.

GitOps takes advantage of immutable infrastructure to minimize the risk of configuration drift and other changes after a deployment and to ensure that the infrastructure maintains its desired state. Together with declarative configuration, immutability also enables the complete recovery of the infrastructure if it crashes. Developers are also increasingly used to immutable infrastructure in another form —– Docker containers are immutable (as a best practice, at least).

GitOps vs. DevOps

Both GitOps and DevOps are designed around the developer experience. While there is some overlap in tools and practices, there are also significant differences between the two.

For one, DevOps is a culture and practice that enables organizations to develop and improve products at high velocity. GitOps is a technique for provisioning and managing infrastructure designed around and tethered to a specific tool: Git. DevOps is mainly concerned with changing an organization’s culture to foster greater collaboration between development and operations teams. GitOps provides tools and a framework to apply DevOps practices such as version control and CI/CD to infrastructure management.

Despite these differences, DevOps and GitOps can easily co-exist within the same organization because of their shared principles, practices and tools. It’s important to note, however, that while an organization using DevOps does not have to adopt GitOps, an organization wanting to adopt GitOps is likely already practicing DevOps.

Using GitOps with Kubernetes

Kubernetes and other modern cloud-native tools are defined declaratively, which is driving the popularity of GitOps. As a declarative system, Kubernetes understands how the ideal cluster configuration should look. It continuously monitors and compares the current state of the system and automatically reconciles it against its desired state.

This methodology lets developers define their ideal state of the system and version control Kubernetes configuration files in Git. The system becomes easier to manage, and it can be rolled back to a previous version if a deployment causes problems. Overall, GitOps facilitates better convergence and end-to-end management of Kubernetes and cloud-native application development, as well as application deployment.

Benefits and Challenges of GitOps

GitOps offers several benefits, including:

GitOps also comes with a few potential challenges:

Getting Started With GitOps

As GitOps uses DevOps practices and tooling, having a mature DevOps culture is a prerequisite for getting started. It ensures developers can get acclimated to GitOps workflows quickly.

The other requirement is infrastructure that can be declaratively managed. For this reason, GitOps is often employed to manage Kubernetes clusters and cloud-native app development. GitOps can be used with other infrastructure and deployment pipelines, such as Ansible, which enables declarative modeling of traditional IT systems.

You will also need tools to implement the GitOps workflow. There are dozens of available GitOps tools, but Flux and ArgoCD are two of the more popular options.

Rather than trying to implement GitOps across your entire ecosystem at once, take an incremental approach. Start with network configuration management, a virtual machine OS, or another resource and define its desired state. Then begin making changes to the current state using infrastructure as code, employing a Git repository to keep track of the resource’s state as it changes, and from there use your CI/CD system to deploy updates. Continue developing a GitOps workflow and documenting processes for your development team until you’re confident applying GitOps to your whole ecosystem.

GitOps Best Practices for Getting Started

Some GitOps principles and best practices include:

The Bottom Line: GitOps is crucial for modern infrastructures

The demands made on modern infrastructures make infrastructure automation a must. GitOps offers an easy way to get started by leveraging the tools and practices your developers are already using. With one small pilot project, you can take the first step toward building a more resilient infrastructure.

FAQs about GitOps

What is GitOps?
GitOps is a set of practices that uses Git as the single source of truth for declarative infrastructure and applications, enabling automated deployment, monitoring, and management.
How does GitOps work?
GitOps works by storing the desired state of systems and applications in Git repositories. Automated processes then ensure that the actual state matches the desired state defined in Git.
What are the benefits of GitOps?
Benefits of GitOps include improved deployment speed, enhanced security, better auditability, and simplified rollback and recovery.
What tools are commonly used for GitOps?
Common tools for GitOps include Git, Kubernetes, and automation tools such as ArgoCD and Flux.
What are the challenges of implementing GitOps?
Challenges of implementing GitOps include managing secrets, handling complex workflows, and ensuring consistency across environments.

Related Articles

Regulatory Compliance 101: What You Need To Know
Learn
6 Minute Read

Regulatory Compliance 101: What You Need To Know

Regulatory compliance: Two words with a lot of weight for any company in operation today. Get the full story on this complex topic here.
Cloud Migration Basics: A Beginner’s Guide
Learn
11 Minute Read

Cloud Migration Basics: A Beginner’s Guide

In this blog post, we'll look at definitions, best practices, and industry trends around cloud migrations.
Predictive vs. Prescriptive Analytics: What’s The Difference?
Learn
5 Minute Read

Predictive vs. Prescriptive Analytics: What’s The Difference?

Data analytics is often broken into four categories — of which predictive and prescriptive are two! Learn what these 2 types of analytics can help your business accomplish.
SIEM vs SOAR: What’s The Difference?
Learn
7 Minute Read

SIEM vs SOAR: What’s The Difference?

SIEM, SOAR and more...understanding security solutions no longer has to be tricky! Learn exactly how SIEM and SOAR work & how to use them together.
DataOps & Data Operations Explained
Learn
7 Minute Read

DataOps & Data Operations Explained

Want to turn data into actual opportunities and paths forward? Let DataOps help you get there! Get the full story here.
The Quantum Threat: Options for Migrating to Quantum Safe Cryptography
Learn
4 Minute Read

The Quantum Threat: Options for Migrating to Quantum Safe Cryptography

You’ve heard that eventually you’ll need to migrate to quantum-safe cryptography. And yet, we're here to tell you one thing: don’t do anything yet.
What is OMB M-21-31?
Learn
6 Minute Read

What is OMB M-21-31?

OMB M-21-31 mandates that federal agencies increase their IT visibility and response capabilities before, during & after cybersecurity incidents. Get all the details here.
Data Mesh Architecture Explained
Learn
7 Minute Read

Data Mesh Architecture Explained

Data mesh might be the solution you need. Want to enable teams to innovate, to own and drive their data? Learn all about data mesh right here.
MITRE ATT&CK: The Complete Guide
Learn
7 Minute Read

MITRE ATT&CK: The Complete Guide

Threat actions are always one step ahead. Get ahead of them with the great information in MITRE ATT&CK, a go-to for all security pros. Get the full story here.