Understanding Git Ops
"GitOps uses Git as a single source of truth to deliver applications and infrastructure"
This is the Basic definition of Gitops, But Gitops is more than this; today, software development, managing infrastructure, and deploying applications efficiently is crucial. So, GitOps is a modern approach that leverages Git for managing infrastructure and applications, bringing together the benefits of version control and automation. In this blog, we'll explore what GitOps is, its benefits, and its key principles.
GitOps is a methodology for managing infrastructure and applications using Git as the single source of truth. It aims to automate the deployment and management of infrastructure and applications by using Git repositories as the primary interface. This means that all changes to the infrastructure and application configurations are made through Git commits.
Let's consider an example of deploying a web application to a Kubernetes cluster, first without GitOps and then with GitOps.
Without GitOps
Manually create Kubernetes manifests (deployment, service, etc.) for the web application.
Use
kubectl apply
to deploy the application to the Kubernetes cluster.Monitor the application manually for any issues or updates.
Manually update the Kubernetes manifests and redeploy the application as needed.
With GitOps
Define Kubernetes manifests (deployment, service, etc.) for the web application in a Git repository.
Use a GitOps tool (e.g., Flux, Argo CD) to monitor the Git repository for changes.
When changes are committed to the Git repository, the GitOps tool automatically applies the changes to the Kubernetes cluster.
The GitOps tool ensures that the desired state of the Kubernetes cluster matches the configuration stored in the Git repository, automatically handling updates and ensuring consistency.
So, GitOps simplifies the deployment and management of applications on Kubernetes by automating the process based on the configurations stored in Git, providing better control, consistency, and efficiency.
Without GitOps: Manual management of Kubernetes manifests and application deployments, leading to potential human errors and inconsistency.
With GitOps: Automated deployment and management of infrastructure and applications, ensuring consistency and reducing manual effort.
Benefits of GitOps
Security: Git repositories provide a secure way to store configuration and infrastructure-as-code (IaC). Access control, encryption, and audit trails can be managed through Git's built-in security features.
GitOps also continuously reconcilng the K8s cluster, with the changes in our Git Repo. So, if there is an unwanted change that is made to our cluster, GitOps is there to override those changes. Any change someone trying to put will get replaced.
Versioning: GitOps leverages Git's version control capabilities, allowing you to track changes, revert to previous versions, and maintain a history of all changes made to your infrastructure and applications.
Automated Upgrades: GitOps enables automated upgrades of your infrastructure and applications. Changes made to the Git repository trigger automated workflows that apply the changes to your environment, ensuring that it stays up-to-date. GitOps contains both a pull & push mechanism.
Auto Healing: GitOps can help with auto-healing by continuously monitoring the desired state defined in your Git repository. If any unwanted changes occur, GitOps tools can automatically detect and correct them to bring the environment back to the desired state.
Continuous Reconciliation: GitOps continuously reconciles the actual state of your infrastructure and applications with the desired state defined in your Git repository. This ensures that your environment is always in sync with the configurations stored in Git.
GitOps workflow
The common GitOps workflow includes,
Git Repository: The Git repository serves as the central source of truth for all configuration and code related to the infrastructure and applications.
Infrastructure as Code (IaC): Configuration for the infrastructure (e.g., Kubernetes manifests, Terraform scripts) is stored in the Git repository as code, allowing for versioning and change tracking.
GitOps Tool: A GitOps tool (e.g., Flux, Argo CD) continuously monitors the Git repository for changes. When changes are detected, the GitOps tool automatically applies those changes to the target environment.
Deployment Pipeline: A deployment pipeline uses Images/builds provided from the CI pipeline(build and package applications, run tests) and deploys them to the target environment. The GitOps tool triggers this pipeline when changes are made to the Git repository.
Cluster: The target environment (e.g., Kubernetes cluster) where the applications are deployed and managed based on the configurations stored in the Git repository.
Observability and Monitoring: Tools for observability and monitoring (e.g., Prometheus, Grafana) are used to monitor the health and performance of the applications and infrastructure deployed through GitOps.
These components work together to automate the deployment and management of infrastructure and applications, providing a reliable and consistent workflow for software delivery.
Ending it with a famous question: Is GitOps for K8s only?
The answer is No, GitOps is not limited to Kubernetes (k8s), but most of the popular GitOps tools, e.g., Argo CD or Flux, target K8s. GitOps is commonly associated with Kubernetes due to its declarative nature and popularity in the container orchestration space, The principles of GitOps can be applied to other infrastructure and application environments as well.
Thanks for reading! I hope you understood these concepts and learned something.
If you have any queries, feel free to reach out to me on LinkedIn.
Subscribe to my newsletter
Read articles from Ritik Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by