Beginner Guide Gitops
Beginner Guide Gitops
Beginner Guide Gitops
• An introduction to GitOps
• The benefits of infrastructure automation
• GitOps best practices
2
Table of contents
Introduction
As software applications become more sophisticated, This eBook will introduce the infrastructure automation
the demands on infrastructure increase. Infrastructure process of GitOps and how it offers an end-to-end solution
teams need to support complex deployments at for designing, changing, and deploying infrastructure.
In this eBook, you’ll also learn:
immense scale and speed. While much of application
development has been automated, infrastructure
• How GitOps works with processes you already use
has remained largely a manual process requiring
in application development
specialized teams. Instead of manual processes, is
• The three components teams need to get started
there a repeatable and reliable way to design, change,
with GitOps
and deploy software environments? Infrastructure-as-
code (IaC) tools like Ansible and Terraform are a good • GitOps best practices and workflows
Organizations with a mature DevOps culture can deploy code to pro- GitOps offers a way to automate and manage infrastructure, and it does
duction hundreds of times per day. While the software development this by using DevOps best practices that many organizations already
lifecycle has been automated, rolling out infrastructure is still largely use, such as version control, code review, and CI/CD pipelines. Having
a manual process. IT teams struggling to keep up with more frequent infrastructure described as code allows you to deploy the same service
deployments is not a new problem. over and over. By using parameterization, it’s possible to deploy the
same service, but to different environments and with different names
When physical hardware was required, infrastructure automation and settings.
was practically impossible. With virtualization, things got a bit easier.
It wasn’t until the cloud went public that large infrastructures could
be completely automated with relative ease. The cloud doesn’t require
hardware and, unlike "traditional" servers and Virtual Machines (VMs),
cloud native services can be created and managed independently
without having to provision a VM or Operating System (OS).
Just because these services are available doesn’t mean teams are able
to use them effectively. AWS alone has over 200 services, and many
companies rely on dozens of them. These services often have many
settings. Using the AWS portal to deploy all services manually is time-
consuming, error prone, and not realistic for large organizations.
AWS has been publicly available since 2006, but even before that time, on-premises infrastruc-
ture management could be a daunting task for IT teams. Various servers ran several applications
and services, and scaling up required IT to manually set up an entire server and reinstall the
same applications with the same settings. Luckily, tools were developed to make this task
a little easier.
The first generation of configuration management (CM) tools, like Puppet and Chef, made it
easy to set up existing servers. IT could spin up a server or VM, install the Puppet or Chef agent,
and let the tool establish everything needed to run applications on the server. These tools ran
on on-premises servers, as well as on cloud servers.
First-generation CM tools were an efficient way to replicate all the steps to set up new
production servers. With these steps now automated, setting up new servers became a lot
easier. However, they still didn’t provision new VMs and didn’t work well with cloud native
infrastructure.
Next came second-generation CM tools like Ansible and SaltStack. These tools can install
software on individual servers, just like the first-gen CM tools, but can also provision VMs
before setting them up. For example, they can c reateten EC2 instances, then install all the
needed software on each of these instances.
One important drawback of these CM tools is that they only provisioned and set up servers
and VMs. They don’t offer solutions for cloud native services.
Amazon CloudFormation appeared around the same as the second-gen CM tools. It doesn’t
handle server setup, but offers the ability to use declarative code to provision an entire AWS
application architecture. There was no longer the need to click through the management console
to manually create resources. You could simply describe your infrastructure as JSON or YAML
and deploy it using the AWS Management Console, the Command-Line Interface (CLI), or the
AWS SDK. But, as an Amazon service, it only works on AWS.
Microsoft Azure offers a similar tool, the Azure Resource Manager (ARM), which allows you to
describe your infrastructure in JSON templates. But much like Amazon CloudFormation and
AWS, ARM only works with Azure services.
When private clouds and other public clouds, like Azure and Google Cloud, gained traction,
many enterprises switched to another cloud or went multicloud in order to not depend on a
single cloud platform. To address this new requirement, multicloud CM tools appeared, such
as Terraform. Simply describe your services and deploy them to multiple clouds/providers/
cloud services.
An upside to these tools is that they unlock the ability to do things like version control, code
review, and continuous integration/continuous delivery (CI/CD) on infrastructure code.
GitOps takes tried-and-true DevOps processes and applies them to infrastructure code.
As the name suggests, it combines Git and operations, or resource management. Git is an
open source version control system that tracks code management changes. Like DevOps,
the goal of GitOps is to use CI/CD to automatically deploy your resources by using code stored
in your Git repositories.
With GitOps, your infrastructure definition code, defined as JSON or YAML and stored in a .git
folder in a project, lives in a Git repository that serves as a single source of truth. Using Git’s
features makes it possible to see the complete change history for the organization’s infrastruc-
ture code, and teams can roll back to an earlier version if necessary.
Git also makes it possible to do code reviews on your infrastructure. Code review is a key DevOps
practice used to ensure that bad application code doesn’t make it into production. This is just
as important for infrastructure code. Bad infrastructure code can accidentally spin up expensive
cloud infrastructure and cost the company thousands of dollars per hour. Likewise, a bad script
could take down your application, resulting in downtime for your services. Code reviews prevent
these mistakes by ensuring multiple people see every change before it’s approved.
What makes GitOps unique is that it’s not a single product, plugin, or platform. GitOps is a frame-
work that helps teams manage IT infrastructure through processes they already use in applica-
tion development. Popular tools are Ansible, Terraform, and Kubernetes, but the GitOps process
is largely technology agnostic (save for Git, of course).
GitOps is suited for a variety of scenarios. GitOps and Kubernetes is a particularly good fit, for
example. Kubernetes works on all major cloud platforms and uses stateless and immutable
containers. Since containerized apps running
in Kubernetes are self-contained, you don’t
need to provision and configure servers for
each app. Provision Kubernetes clusters and
other needed infrastructure, like databases
and networking, using Terraform.
For teams that are used to making small, manual changes to infrastructure, adopting a process
like GitOps can be a big adjustment. GitOps is a framework that requires infrastructure teams
to adopt new habits, and lose old habits. This can take some time and may not come naturally
to every team. Having best practices that are referenced frequently will be helpful in committing
to the long term strategy of GitOps.
Document what you can’t automate Outline a code review and merge request process
It’s not always possible to automate everything. For example, Azure has It’s important to familiarize GitOps teams with Git and code reviews.
some (usually newer) settings that are not yet added to ARM templates. Some teams already use a Git repository as a place to store config code,
A common workaround is to use PowerShell. but don’t use features like merge requests. As a starting point, take a
look at the code review guidelines for the GitLab open source project.
Another example is when working with third-party providers. Imagine This project can give you a sense for the types of information you'll
working with a supplier who needs to manually approve-list your IP want to eventually add to your code review guidelines.
addresses. An approve-list request can only be supplied by a manager.
The manual action for every new service and environment is to look up Before approving a merge request, set a minimum number of revie-
the IP address, pass it on to your manager, and have them email it to wers so all code is reviewed by at least a few members of the team.
the supplier. Make sure such processes are very well-documented.
For teams new to GitOps, another option is to set up "optional
In all likelihood, you'll always have some legacy environments that reviews" rather than set up "required blocking reviews". Since this
need manual attention. Document these instances so that they’re a new process, take some time to get used to doing code reviews and
accounted for. develop a good cadence. Once teams are familiar with the toolset
and practices, implement mandatory reviews to ensure code reviews
happen every time.
Tools like Chef, Puppet, and Ansible have features like "diff alert,"
which notifies you when your services differ from your configuration
code. Using tools such as Kubediff and Terradiff give you the same
features for Kubernetes and Terraform.
Google, one of the largest tech companies in the world, uses a single
repo for all code. HashiCorp recommends that each repository conta-
ining Terraform code be a manageable chunk of infrastructure,
such as an application, service, or specific type of infrastructure (like
common networking infrastructure). The definition of "manageable"
can vary, of course.
Set up your CI/CD to first validate infrastructure code, such as by using the Terraform validate
command or a linter for JSON files. Your infrastructure code should be handled as if it is produc-
tion code. You want your production code to be clean and consistent.
When someone commits invalid code, make sure the build or validation fails and the team
is immediately notified. This allows the team to quickly solve the issue by either applying a fix
or rolling back the commit. If you’re making small changes, that also makes it easier to find
problems.
If the code is valid, the CI/CD should run any commands necessary to provision the infrastructure
defined in the config code. For example, the Terraform apply command or AWS update-stack
for CloudFormation.
To see a sample GitOps project that uses Terraform, CI/CD, and Kubernetes, you can visit our
GitOps-Demo Group. From there, we’ve provided links to Terraform security recommendations,
Terraform code to represent each configuration for three major cloud providers, and instructions
for reproducing this demo within your own group.
GitOps isn’t magic: It just takes IaC ops tools you already know and wraps them in a
DevOps-style workflow. This allows for better revision tracking, fewer costly errors, and
quick, automated infrastructure deployments that can be repeated for a multi-environment
or even multicloud setup.
If you’d like to see how we can help you
By adopting GitOps, organizations improve the developer experience because often-dreaded get started with GitOps, sign up to try
releases become fully automated, allowing developers to focus on just their code. Teams elimi- GitLab free for 30 days.
nate or minimize manual steps and make deployments repeatable and reliable.
Start your GitLab free trial
Infrastructure maintenance often becomes a problem that takes up a lot of time. By fully
automating this process, infrastructure can be elastic and keep up with frequent application
deployments.
GitOps also improves security and standardization. By practicing GitOps, developers have no
need to manually access cloud resources and additional security checks can be put in place at
the code level in CI/CD pipelines.
GitLab can help you get started with a GitOps workflow. From GitLab, you can manage physical,
virtual, and cloud native infrastructures (including Kubernetes and serverless technologies).
GitLab also has tight integrations with industry-leading infrastructure automation tools like
Terraform, AWS Cloud Formation, Ansible, Chef, Puppet, and others. In addition to a Git repo-
sitory, GitLab offers CI/CD, merge requests, and single sign-on simplicity so that everyone can
collaborate and deploy from one platform to any cloud provider.
About GitLab
GitLab is a DevOps platform built from the ground up as a single application for
all stages of the DevOps lifecycle enabling Product, Development, QA, Security,
and Operations teams to work concurrently on the same project.
GitLab provides teams a single data store, one user interface, and one
permission model across the DevOps lifecycle allowing teams to collaborate
and work on a project from a single conversation, significantly reducing cycle
time and focus exclusively on building great software quickly.