When managing declarative infrastructure, such as Kubernetes, there is a risk of configuration drift, where the actual state of the infrastructure diverges from the desired state defined in code.
GitOps addresses this challenge by using Git as the single source of truth for both application and infrastructure configurations.
How GitOps Works
In case of Kubernetes, there is an agent (like ArgoCD) that continuously monitors the Git repository for changes. When a change is detected, the agent automatically applies the new configuration to the Kubernetes cluster, ensuring that the actual state of the cluster matches the desired state defined in Git.
graph LR A[Developer] B[Git Repository] C[GitOps Agent] D[Kubernetes Cluster] A -->|Push| B B -->|Monitored| C C -->|Apply| D D -.->|Drift| C classDef nodeStyle fill:#4A90E2,stroke:#2E5C8A,stroke-width:4px,color:#fff,padding:20px class A,B,C,D nodeStyle
If the cluster changes outside of Git (for example, if someone manually modifies a resource in the cluster), the agent will detect this drift and revert the change to align with the configuration in Git.