GitOps is a method that involves implementing DevOps so that Git forms the single source of truth. Instead of maintaining a long list of scripts and tooling to support this, GitOps focuses on writing declarative code for everything, including the infrastructure, configuration, and application code. This means you can spin anything out of thin air by simply using the Git repository. The idea is that you declare what you need in your Git repository, and there is tooling behind the scenes that ensures the desired state is always maintained in the running application and infrastructure surrounding it. The code to spin up the tooling also resides in Git, and you don’t have anything outside of Git. This means everything, including the tooling, is automated in this process.
While GitOps also enables DevOps within the organization, it primarily focuses on using Git to manage infrastructure provisioning and application software deployments. DevOps is a broad term that contains a set of principles, processes, and tools to enable developers and operations teams to work seamlessly and shorten the development life cycle, with an end goal to deliver better software more quickly using a CI/CD cycle. While GitOps relies heavily on Git and its features and always looks to Git for versioning, finding configuration drift, and only applying deltas, DevOps is, as such, agnostic of any tool and focuses more on the concepts and processes. Therefore, you can implement DevOps without using Git, but you cannot implement GitOps without Git. Put simply, GitOps implements DevOps, but the reverse may not always be true.
Why GitOps?
GitOps provides us with the following benefits:
- It deploys better software more quickly: GitOps offers simplicity in delivering software. You don’t have to worry about what tool you need for the deployment type. Instead, you can commit your changes in Git, and the behind-the-scenes tooling automatically deploys it.
- It provides faster recovery from errors: If you happen to make an error in deployment (for example, a wrong commit), you can easily roll it back using git revert and restore your environment. The idea is that you don’t need to learn anything else apart from Git to do a rollout or a rollback.
- It offers better credential management: With GitOps, you don’t need to store your credentials in different places for your deployments to work. You simply need to provide the tooling access to your Git repository and the binary repository, and GitOps will take care of the rest. You can keep your environment completely secure by restricting your developers’ access to it and providing them access to Git instead.
- Deployments are self-documenting: Because everything is kept within Git, which records all commits, the deployments are automatically self-documenting. You can know exactly who deployed what at what time by simply looking at the commit history.
- It promotes shared ownership and knowledge: As Git forms the single source of truth for all code and configurations within the organization, teams have a single place to understand how things are implemented without ambiguity and dependency on other team members. This helps promote the shared ownership of the code and knowledge within the team.
Now that we know about the benefits of GitOps, let’s look at its key principles.