As technology continues to advance coupled with increased user demands, software companies are responsible for shipping products faster, more securely, and in a distributed network.
This has led to the birth of DevOps, which promotes collaboration amongst team members. And also the use of containers in frequent processing and updates in applications. This sometimes leads to configuration inconsistencies requiring hours of troubleshooting.
Weaveworks introduced GitOps to fix these challenges and increase performance in software development.
This article will cover the definition of GitOps, principles, tools, how GitOps works, and its benefits, and finally, compare GitOps and DevOps.
GitOps is a software development framework used for the continuous deployment of applications. And ensuring that these updates are up-to-date with the software infrastructure using a git repository.
GitOps is a set of deployment practices that combines DevOps best practices and applies them to infrastructure automation.
GitOps is not an update to DevOps but a subset of DevOps. This means teams could use the GitOps workflow in DevOps.
GitOps ensures the live syncing of changes in an application using a Git repository. So the IT infrastructure of the application is always up-to-date with the constant updates made in the application. This makes the software production process faster and more efficient.
Weaveworks introduced GitOps — a Kubernetes Enterprise Management Solution, in 2017. So when we make updates, we will merge them in a git repository which will automatically sync with the live system and infrastructure.
There are four principles of GitOps, and according to Open GitOps, they are:
- Versioned And Immutable
- Pulled Automatically
- Continuously Reconciled (Source: opengitOps)
GitOps uses a declarative Approach. This approach describes the "what" of the gitOps model and not the "how" of the control flow. So we can write our code in the infrastructure and application as facts in Git, which becomes the single source of truth.
With the design of the git model, we can track changes and move applications back and forth to the Kubernetes cluster. We will also be able to 'revert' changes in failure cases.
Versioned and Immutable
With Git being the single source of truth and because it is a version control system, our declarative code becomes immutable and versioned.
They carry all the activities out on Git, providing transparency and clarity. So we can merge recent changes or roll back old changes. This is helpful for troubleshooting as it offers an audit log of activities carried out on the repository.
After declaring the desired states in the system, we will need to automate the system to apply any changes made in the states.
This is one of the best things about GitOps, the declared states are separate from the production environment. That way, the process and the product work in different environments.
When we have declared the states, and it is versioned. We can use software agents like CI/CD pipelines or operators to monitor changes.
These agents continuously reconcile actual changes that differ from the expected states. They also alert us if there is an unexpected change or drift from the normal.
An example of GitOps in a real-life scenario will be:
If a team is building an application and their source code is on the git repository. And they wish to add new features to their application. They will make these changes and update it. The operator or CI/CD tool will inform the infrastructure of these changes. And it will update the infrastructure automatically.
But if they observe that the features they added introduced new bugs in their application. And it's becoming a hassle for the users. They can quickly 'revert' the features they made using the git repository.
Note: Some companies may use CI/CD tools or an operator to inform the infrastructure. It depends on the type of deployment they are running.
There are two types of deployments which are push-based deployments and pull-based deployments.
In push-based deployments, the Kubernetes Yaml is contained in the application repository and the source code. This type of deployment uses CI/CD tools. Whenever updates are merged in the git repository, the infrastructure becomes updated too.
In pull-based deployments, it has the same structure as push-based deployments, but operators like Flux and ArgoCD take over the role of the CI/CD tools. Whenever updates are made, it compares and updates the infrastructure automatically.
To add a new feature in GitOps, these are vital steps:
Create issues: We will create an issue ticket for the new feature in the application repo and infrastructure repo, respectively.
Create branches: Then, we will create a branch for the feature in the application repo and infrastructure repo and commit the code in each branch.
Code review and testing: We will create pull requests, so we can test the codes while submitting them for review. Our team members will review the code. The CI/CD pipeline will run automated tests and check if the code passes all tests and checks. And we resolve every comment by our team members. Then the team lead will approve the merge.
Deploy the merge: After they approve the merge to the main branch. During the deployment, the CI/CD pipeline will run more tests to determine if everything is in order.
Final Updates: After the merge, the infrastructure will update to sync with the live system while the application repo deploys the code.
Here are some benefits of GitOps:
With the automation applied to the infrastructure and source code, it is much faster for developers to make updates to an application.
They can fix bugs and add new features, making up to 30 - 100 updates to their application daily. And it would sync these updates with the live application. Developers can push updates to the application if it disrupts the flow of the application. They can quickly 'revert' their changes in the Git history.
GitOps helps you to create a standard infrastructure for deployments. It creates a consistent workflow which will make the CI/CD pipeline more visible.
This is because the Git repository is the single source of truth. The Git repository records all the activities on the application, which the team can use for compliance and cross-checking who made changes and when.
This makes GitOps a reliable information tool; companies can use it to onboard new developers. When new intakes go through the git repository, they can quickly become informed and acquainted with the workflow.
Ease of adoption
Because developers are already familiar with the tools used in the workflow, such as the Git repository, GitOps is relatively simple to adopt. So introducing the Ops part to Git is more accessible, and developers can adapt to the workflow.
GitOps tools are secure and integrated into a central git repository. GitOps also helps to enforce authorization in the infrastructure and the source code. This will help the team leader direct access to certain parts of the repository only to those they want.
Some of the tools that teams could use for GitOps include,
A Git repository like GitHub, Bitbucket, GitLab, etc.
A CI/CD pipeline platform like Jenkins, Circle CI.
An operator like Flux, ArgoCD.
An Orchestration system like Kubernetes, Terraform.
As mentioned earlier, GitOps will not replace DevOps, but it is under DevOps.
GitOps works with containerized applications, while DevOps works with any application.
DevOps is more of a paradigm of how teams should collaborate for better results. While GitOps uses Git as a central tool for its operations and automation.
DevOps focuses more on best practices for organizations to apply when building their products.
GitOps is a framework, and organizations could use tools like Git to automate infrastructure and pull/merge requests.
After reviewing what GitOps is and does. We can see that it is a powerful workflow that could manage the yet-increasing complex nature of cloud technologies.
That way, companies can respond to customer and market demands faster and stand out amongst their competitors.
Many companies could adopt this tool as time goes on. Some say it is the future, but we could only guess that.