What is GitOps in easy way ??


Here we will discuss: "What is GitOps", and "What are its 4 important principles". And lastly, "Why GitOps operator follow a pull-based model ?".

What is GitOps ??



GitOps is made up of two words: Git and Ops. Git is where you keep your desired manifest(or configurations) that you want to deploy in your cluster(or environment). And Ops refers to Operation. Operation refers to the environment where the things are operated to ensure that the actual state or live state of that environment must be the same as the desired state in the git. To achieve that from the actual state to the desired state an operation is performed inside the environment.  Such an environment could be a Kubernetes cluster. So, anything that you want to deploy in the Kubernetes simply put it in the git. From git, the GitOps operator(i.e. Argo CD) will deploy to the Kubernetes cluster. To understand the GitOps better we need to understand 4 principles of it:

4 Principles of GitOps:

1. Declarative Vs Imperative approach:

GitOps demands the entire system including infrastructure and application manifest to be declared in a declarative state. Declarative means an end state or desired state we want to achieve is defined via manifest and placed in Git.  For example, suppose you want to start 3 containers, to do that imperatively, you need to run commands manually. Whereas declaratively, you only need to declare the “number of containers” in the manifest file and unlike imperatively you don’t need to remember commands.
Once you declare your desired state in the manifest, it needs to be pushed to Git, and from Git, it will be automatically fetched by the GitOps operator and pushed to the environment or cluster.

NOTE: Why does it discourage the use of imperative approaches ??

The imperative approach uses a series of explicit commands to change the desired state which makes reconciliation difficult because it does not store any state.

2. Git:

All the declarative files also known as the desired state are stored in a git repository. Git provides version control and also enforces immutability. Since the desired state is stored and versioned it is essentially known as the source of truth. Once we store the desired state in git, we must allow any changes to the state to be applied automatically.

3. GitOps Operator:

Also known as a Software agent, as the Git repo is updated by the team members via pull request, it's now the duty of a software agent to pull these new changes every 3 minutes from Git and update the state of the target environment through reconciliation.

NOTE:
  • Later we will understand that GitOps Operators work on a Pull-based Model.
  • Live State or Current state: Actual state deployed in the environment or cluster.
  • Target State or Desired state: The desired state is represented resent in the Git repository.

So, the job of the software agent is to implement reconciliation in order to sync the live state of the cluster with the desired state present in Git.

NOTE: The GitOps operator runs in one of the clusters and can make or push changes to multiple clusters as well.

4. Reconciliation:

The continuous looping in a defined interval to ensure that the desired state described in the Git repository with the Live state in the cluster is known as Reconciliation. It is implemented by the software agent known as the GitOps operator. Later in Argo CD architecture, we will learn that the Application Controller (core components of Argo CD ) is nothing but the GitOps operator.
By default, every 3 minutes the GitOps operator looks at the git repo and reconciles it.

The reconciliation involves 3 steps:




  • Observe:
    • The GitOps operator checks the git repo for any changes in the desired state.
  • Diff:
    • In this state, the operator compares the resources received from Git to the live state of the cluster.
  • Act:
    • It uses the reconciliation function and tries to match the actual state to the desired state.


This control loop is being carried every time the reconciliation loop is carried by the GitOps operator.

NOTE:
  • Control loop == Obser + Diff + Action
  • The GitOps operator also makes sure that the entire system is self-healing to reduce the risk of human errors.

Overall when we look at the term called "GitOps". It means considering Git as a source of truth. From where the operation is carried out by the GitOps operator every 3 minutes to achieve the desired state via the reconciliation process. Basically, GitOps is limited to the Cloud-Native environment i.e. Kubernetes environment only, that's why it is considered to be part of DevOps.

Why GitOps Operator follow a pull-based model rather than a push-based model ??

In the Pull-base model, the GitOps operator itself pulls the changes from Git every 3 minutes. Whereas in the push-based model, Git pushes the changes to the environments or cluster.

For the push-based model, the "CI/CD" needs to have read-write access to the Kubernetes cluster. This raises a potential issue and hence not recommended. Apart from that CI/CD system also has read-write access to the container registry.

Whereas the pull-based model has read-write access to the container registry but not to the Kubernetes cluster.

Managing secrets in a pull-based model is a bit hard. As per the GitOps principle, the secret also has to be declared in a git repo as plaintext(i.e. base64). But we can't do so, to avoid the plain-text secret we use the sealed secret or Harshicorp vault or many more to encrypt the secret and then push to git.

Till now we have learned about GiOps principle and pull-based mode. Next, we will learn about Argo CD. That's all for today. Great to see you all upgrading your knowledge. Keep growing and keep learning !!



Comments

All Post

Argo CD 101

Logging ??

AWS and its Services ??

Observability 101

Prometheus Architecture...

Why need of Cloud Computing ??

Build a Slack activity dashboard with Metabase

Monitoring 101

Application Resource in Argo CD