GitOps is a paradigm aimed at implementing Continuous Deployment and/or Continuous Delivery for Cloud Native applications. Through the use of tools that the developer is already familiar with, it focuses on an experience that also sees the developer involved in infrastructure-related activities.
We can think of GitOps as a collection of best practices for managing the delivery of containerized applications, together with the infrastructure on which they run.
GitOps is based on 3 key principles:
So a new actor is needed in order to implement GitOps in Kubernetes: the GitOps Operator.
THIS MAY INTEREST YOU: 3 mistakes to avoid when adopting Kubernetes
As we already mentioned, a new actor is needed: the GitOps operator. In other words, a Kubernetes operator which follows the loop control pattern of the Kubernetes controller and handles the automation aspect of delivery and monitoring. Several GitOps operators are currently available on the market, the main ones being Flux CD, Argo CD and Jenkins-X.
Jenkins-X is an open-source project with enterprise support offered by CloudBees, and is part of the Continuous Delivery Foundation (CDF).
So why are we telling you this? It is not uncommon that, after a few releases, some premium features switch over to the free version. So it’s definitely worth keeping an eye on this GitLab feature and on how the tool will evolve in its free version.
Before looking at the GitOps CI/CD pipeline, let’s take a look at a typical Kubernetes CI/CD pipeline, also known as the Push Model.
Credits: GitOps, Push-Based Deployments
This model follows a pipeline which, as you can see, we can defined as unilinear and unidirectional: it starts from the developer, follows all the steps of the CI and, finally, it is the same CI tool that also handles the Continuous Deployment of the application in its target environment.
Although not inherently wrong, this process can present some weaknesses: first of all, the need to provide the target environment credentials to the CI/CD tool. Second, we see a CI tool that is unable to detect/alert us of discrepancies between the desired state and the current one and forces us to install a second tool that is in charge of monitoring the state of the application.
Credits: GitOps, Pull-Based Deployments
In the Pull-Based Model, and likewise in the CI/CD GitOps pipeline model, we see a first main difference, namely the presence of two repositories located at the beginning and end of the CI process. In this model, in fact, the CI tool no longer takes care of the deployment. Instead, this task will fall on an operator like those seen previously, installed in the target environment. Listening for any changes made in the registry docker and in the repository environment, the tool will ensure that the current state of the environment coincides with that of the repository environment, in other words, the desired state.
So let’s take a look and see how in this model the unidirectional and unilinear nature of the Push-Based model are circumvented, thus enhancing its security and efficiency.
No doubt, GitOps can offer many benefits. First, it makes the system fully observable, both by you and by an automated tool. It assures you that what you see in the repository environment is perfectly in line with the Kubernetes cluster, independently making the necessary implementations to match the current state of the system with the desired state (consequently also increasing the verifiability of the system!).
Moreover, GitOps shares an essential benefit with Kubernetes: the declarative model on which the work of the operators is based, thanks to which you can see an increase in productivity. Finally, the Pull model enhances system security by simplifying the problem of having to expose the Kubernetes APIs to your Continuous Integration.
To be absolutely sure that you can take full advantage of these benefits, however, attention must be paid to aspects that can lead to problems if not properly managed. Indeed, it is important to leverage the repository environment and pipelines to prevent, as much as possible, the simultaneous push to the same repository. If Git found that the remote repository was no longer aligned because, in the meantime, another pipeline pushed on the same repository and on the same branch, it would no longer be able to push the changes.
So what are our recommendations to avoid these problems?
First, if possible, we recommend that you always use two repositories, one for your application code and the other as storage for your manifests. Moreover, always remember that you should never store sensitive data in the repository environment. It is true that GitHub helps make your system more secure, but it is still a good idea to take this precaution.
By following these two simple tips and best practices, you can create modern and Cloud Native applications, enjoying all the various benefits that the GitOps paradigm has to offer and will continue to offer with its ever-growing development.