What is GitOps?
MediumGitOpsArgo CDKubernetes
What is GitOps, and how does a tool like Argo CD or Flux work?
TL;DR
GitOps means Git is the single source of truth for the desired state of your system (Kubernetes manifests, Helm values, Kustomize overlays), and an agent inside the cluster continuously pulls that state and reconciles the cluster to match it. You deploy by merging a pull request, not by running kubectl apply from a laptop or CI. Argo CD and Flux watch the repo, apply changes, show what's out of sync, and can self-heal drift by reverting manual changes.
Key points
- Pull vs push: in push-based CD, the CI pipeline holds cluster credentials and pushes changes. In GitOps the cluster pulls, so CI never needs production cluster credentials.
- Benefits: an audit trail (Git history), review via pull requests, easy rollback (
git revert), and drift detection. - Typical flow: CI builds and tests the app, pushes image
api:abc123, then opens a PR (or commits) bumping the tag in the config repo → after merge, Argo CD syncs it. - Keep app code and deployment config in separate repos (or folders), so config changes don't trigger app builds.
- Secrets still need care: Sealed Secrets, SOPS, or the External Secrets Operator.
- Progressive delivery integrates through Argo Rollouts or Flagger.
- Scales to many clusters with ApplicationSets (Argo CD).
Example
yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: api-prod, namespace: argocd }
spec:
project: default
source:
repoURL: https://github.com/acme/deploy-config
path: apps/api/overlays/prod
targetRevision: main
destination: { server: https://kubernetes.default.svc, namespace: api }
syncPolicy:
automated: { prune: true, selfHeal: true }Common follow-ups
- How do you do an emergency fix? Still through Git (a fast-tracked PR). A manual
kubectlchange would be reverted by self-heal anyway. - Does GitOps replace CI? No. CI builds, tests and publishes artifacts; GitOps handles deploying them.
What interviewers look for
Tip
Git as source of truth, pull-based reconciliation, why it's more secure than CI pushing to clusters, and a concrete release flow.
- Red flag: "GitOps means we keep YAML in Git" but still deploy with
kubectlfrom CI.