GitOps & ArgoCD

Ayca Akcay
Turk Telekom Bulut Teknolojileri
6 min readApr 8, 2022

Hi everyone, I will tell you about Argo CD with what I learned from an excellent video I came across while trying to get to know Argo CD. You can find the source at the references[1].

What is GitOps?

GitOps is an operational framework that takes DevOps best practices used for application development such as version control, collaboration, compliance, and CI/CD tooling, and applies them to infrastructure automation. While the software development lifecycle has been automated, infrastructure has remained a largely manual process that requires specialized teams. With the demands made on today’s infrastructure, it has become increasingly crucial to implement infrastructure automation. Modern infrastructure needs to be elastic so that it can effectively manage cloud resources that are needed for continuous deployments.

GitOps: versioned CI/CD on top of the declarative infrastructure. Stop scripting and start shipping.

— Kelsey Hightower

With GitOps, you use git -an open-source version control system- as the single source of truth for declarative infrastructure and applications code. No matter which infrastructure or application should be deployed or configured, the source for it is stored in git.

To apply the current state of what is configured to real-world objects outside of git (like Kubernetes clusters, VMs, etc.), pipelines are added. With pipelines, you are able to execute tasks on specific git events (like new commits in a branch, the creation of tags, or merging into an existing branch). In combination with other features, like for example merge requests git turns into your central action operation center.

Gitops has 3 main components:

  • Infrastructure as Code(IaC) GitOps uses the Git repository as a “single source of truth” for infrastructure definitions. Git is an open-source version control system that tracks code management changes, and a Git repository is a “.git” folder in a project that tracks all changes made to files in a project over time. Infrastructure as Code(IaC) is the practice of storing the entire infrastructure configuration as code. (config, policy, etc.)
  • Merge Requests(MRS) GitOps uses Merge requests as the change mechanism for all infrastructure updates. (code review, collaboration, and approvals)
  • CI/CD: GitOps automates infrastructure updates using Git workflow with continuous integration and continuous delivery (CI/CD). When the new code is merged, the CI/CD Pipeline triggers the change in the environment. Changes are implemented automatically.
from https://about.gitlab.com

We started to adapt our workflows, integrated new tools, and built pipelines to automate whatever had to be automated.

And then Argo CD comes to the stage.

What is ArgoCD?

“Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.”

There is a point out there that is understanding the ArgoCD as a CD tool. First of all, understand how a continuous delivery tool is implemented in most projects using common tools like Jenkins or GitLab CI/CD, and then see how ArgoCD compares to them.

So ArgoCD is it another CD tool or what is so special about it?

We have a microservices application and we are running it in a Kubernetes cluster. When things change in the application code like a new feature or a bug fix gets added to the CI pipeline on Jenkins for example, it will be automatically triggered and will test the changes, build a next docker image and push it to the Docker repository. How does this new image get deployed to Kubernetes?

We update the application deployment YAML file for Kubernetes with the new image tag and this YAML file then should be applied to Kubernetes. In most projects, these steps are the continuation of the CI pipeline. So after the image gets pushed to the repository Jenkins will update the deployment YAML file for the application and using kubectl tool, for example, will apply the update deployment file to the Kubernetes. However, there are a couple of challenges with this approach. First, of all, you need to install and set up tools like kubectl or helm, etc. to access the Kubernetes cluster and execute changes on those build automation tools. You also need to configure access to Kubernetes for these tools. Because kubectl is just the Kubernetes client and in order for it to connect to Kubernetes it needs to provide some credentials. So you need to configure credentials for the Kubernetes cluster in Jenkins. This is not the only configuration effort, this is also a security challenge. Because you need to give your credentials to external services and tools. Another challenge is, that once Jenkins deploys the application to Kubernetes or it applies any changes to Kubernetes configuration it has no further visibility of the deployment status. So once kubectl application was executed Jenkins does not know the status of the execution. Did the application actually get created, is it in a healthy status or is it actually failing to start?

Argo CD was built for this specific use case to make continuous delivery to the Kubernetes cluster specifically more efficient with using GitOps principles.

How does Argo CD make it happen?

  • Deploy ArgoCD in the K8s cluster
  • Configure ArgoCD to track the Git repository
  • ArgoCD monitors for any changes and applies automatically

It enables developers to manage both infrastructure configuration and application updates in one system.

  • GitOps agent — ArgoCD is responsible for pulling updated code from Git repositories and deploying it directly to Kubernetes resources. It manages both infrastructure configuration and application updates in one system.
  • Custom Resource Definitions (CRD) — ArgoCD operates in its own namespace within a Kubernetes cluster. It provides its own CRDs that extend the Kubernetes API and make it possible to define the desired application state in a declarative way. Based on the instructions in a Git repo or a Helm repo, ArgoCD uses its CRDs to implement the changes within its dedicated namespace.
  • CLI — ArgoCD offers a powerful CLI that lets you create YAML resource definitions very simply.
  • User Interface — ArgoCD is unique in that it offers a convenient web-based UI that lets you do the same thing, define an application and ask ArgoCD to create the relevant YAML configurations. It also lets you visualize the resulting Kubernetes configuration in terms of pods and containers.

How ArgoCD Works

ArgoCD automatically deploys the desired state of an application in a specified target environment. Updates are traceable as tags, branches, or pinned specific versions of a manifest at Git commits.

ArgoCD is a Kubernetes controller, responsible for continuously monitoring all running applications and comparing their live state to the desired state specified in the Git repository. It identifies deployed applications with a live state that deviates from the desired state as out of sync. ArgoCD reports the deviations and provides visualizations to help developers manually or automatically sync the live state with the desired state.

ArgoCD can automatically apply any change to the desired state in the Git repository to the target environment, ensuring the applications remain in sync.

In my next article, I will talk about the installation and use of ArgoCD.

To be continued…🐙

--

--