LI Git Terra
LI Git Terra
• • An introduction to GitOps
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
teams need to support complex deployments at solution for designing, changing, and deploying
immense scale and speed. While much of application infrastructure. In this eBook, you’ll also learn:
development has been automated, infrastructure
has remained largely a manual process requiring • How GitOps works with processes you already use
specialized teams. Instead of manual processes, is in application development
there a repeatable and reliable way to design, change, • The three components teams need to get started
and deploy software environments? Infrastructure- with GitOps
as-code (IaC) tools like Ansible and Terraform are
• GitOps best practices and workflows
a good start, but they don’t solve the entire problem.
Teams need a prescriptive workflow that puts IaC into
action automatically.
Organizations with a mature DevOps culture can deploy code to production the AWS portal to deploy all services manually is time-consuming, error
hundreds of times per day. While the software development lifecycle has prone, and not realistic for large organizations.
been automated, rolling out infrastructure is still largely a manual process.
IT teams struggling to keep up with more frequent deployments is not a GitOps offers a way to automate and manage infrastructure, and it does
new problem. this by using DevOps best practices that many organizations already
use, such as version control, code review, and CI/CD pipelines. Having
When physical hardware was required, infrastructure automation infrastructure described as code allows you to deploy the same service
was practically impossible. With virtualization, things got a bit easier. over and over. By using parameterization, it’s possible to deploy the
It wasn’t until the cloud went public that large infrastructures could same service, but to different environments and with different names
be completely automated with relative ease. The cloud doesn’t require and settings.
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
AWS has been publicly available since 2006, but even before that time, on-premises infrastructure
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 create ten 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.
Try
Try GitLab
GitLab free
free for
for 30
30 days
days >> Follow us:
7
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 infrastructure
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.
Try
Try GitLab
GitLab free
free for
for 30
30 days
days >> Follow us:
8
A GitOps framework makes infrastructure automation possible, and while Less error prone. Infrastructure definition is codified and
automation has value in itself, it’s not the only advantage to GitOps. repeatable, making it less prone to human error. With code
Organizations that adopt GitOps enjoy other benefits that can make a long reviews and collaboration in merge requests, errors can
term impact. be identified and corrected before they ever make it to
production.
Collaboration on infrastructure changes. Since every
Reduced costs and downtime. Automation of infrastructure
change will go through the same change/merge request/
definition and testing eliminates manual tasks, improves
review/approval process, senior engineers can focus on
productivity, and reduces downtime due to built-in revert/
other areas beyond the critical infrastructure management.
rollback capability. Automation also allows for infrastructure
Faster time to market. Execution via code is faster than teams to better manage cloud resources, which can also
manual point and click. Test cases are automated and improve cloud costs.
repeatable, so stable environments can be delivered rapidly.
Improved access control. There's no need to give credentials
to all infrastructure components since changes are automated
Simplified auditing. When infrastructure changes are
(only CI/CD needs access).
conducted manually across a set of multiple interfaces it
can make auditing complex and time consuming. Data needs
Collaboration with compliance. In heavily regulated contexts
to be pulled from multiple places and normalized in order to
policy often dictates that the number of people who can enact
conduct the audit. Using GitOps, all changes to environments
changes to a product environment remains as small as possible.
are stored in the git log making audits simple.
With GitOps almost anyone can propose a change via merge
Less risk. All changes to infrastructure are tracked through request opening the scope of collaboration broadly while keeping
merge requests, and changes can be rolled back to a the ability to strictly limit the number of people with the ability to
previous state. merge to the production branch to maintain compliance.
GitOps is suited for a variety of scenarios. GitOps and Continuous Inegration tool
Kubernetes is a particularly good fit, for example. Kubernetes
works on all major cloud platforms and uses stateless and
Continuous Delivery tool
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
Container Registry
clusters and other needed infrastructure, like databases
and networking, using Terraform.
Configuration manager
Deploying stateful applications requires some additional
consideration for persisting data to external services, like
an Amazon Aurora database instance or a Redis cache. Infrastructure provisioning
Try
Try GitLab
GitLab free
free for
for 30
30 days
days >> Follow us:
12
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. This
Another example is when working with third-party providers. Imagine project can give you a sense for the types of information you'll want to
working with a supplier who needs to manually approve-list your IP 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 reviewers
the IP address, pass it on to your manager, and have them email it to the so all code is reviewed by at least a few members of the team.
supplier. Make sure such processes are very well-documented.
For teams new to GitOps, another option is to set up "optional reviews"
In all likelihood, you'll always have some legacy environments that need rather than set up "required blocking reviews". Since this a new process,
manual attention. Document these instances so that they’re accounted for. take some time to get used to doing code reviews and develop a good
cadence. Once teams are familiar with the toolset and practices, imple-
ment mandatory reviews to ensure code reviews happen every time.
As we've recommended elsewhere – start small and simple. If you start out
with a complex set of guidelines, no one will want to adopt your process.
Focus more on adoption than on doing what's best. Over time, iterate on
code review guidelines to make them more robust and complete.
Google, one of the largest tech companies in the world, uses a single
repo for all code. HashiCorp recommends that each repository containing
Terraform code be a manageable chunk of infrastructure, such as an appli-
cation, 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 production
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 infra-
structure deployments that can be repeated for a multi-environment or even multicloud setup.
Infrastructure maintenance often becomes a problem that takes up a lot of time. By fully automating
If you’d like to see how we
this process, infrastructure can be elastic and keep up with frequent application deployments.
can help you get started with
GitOps, sign up to try GitLab
GitOps also improves security and standardization. By practicing GitOps, developers have no need
free for 30 days.
to manually access cloud resources and additional security checks can be put in place at the code
level in CI/CD pipelines. Start your GitLab free trial
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 repository, 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.