Skip to content
Ship It
Learn/Delivery layer

GitOps

GitOps isn't an alternative to canary or blue-green. It decides how a change reaches the cluster at all. Git holds the desired state, and an agent in the cluster (Argo CD here) keeps pulling it and making reality match.

Try it

Ship, drift, revert
Gitdesired state
  1. a1f3c2eshop: deploy v1HEAD
replicas: 4
image: shop:v1
pull
Argo CDcompares and syncs
SyncSynced
HealthHealthy
Target a1f3c2e · selfHeal on
apply
Clusterlive state
v1v1v1v1
4 pods
  1. argoApplication shop is Synced and Healthy

Try kubectl scale in prod with selfHeal on, then again with it off. With selfHeal off, the drift stays until someone syncs.

The four principles

From the CNCF OpenGitOps project
1

Declarative

You describe the state you want, not the commands to get there.

2

Versioned and immutable

Desired state lives in Git, with full history. Every change is a commit you can review, audit and revert.

3

Pulled automatically

An agent in the environment fetches the desired state. Nothing outside pushes into it.

4

Continuously reconciled

The agent keeps comparing live state with desired state and corrects any drift.

Push vs pull

Push (classic CI/CD)Pull (GitOps)
Who changes the clusterCI pipeline runs kubectl or helmAn agent inside the cluster (Argo CD, Flux)
Cluster credentialsStored in CI, outside the clusterStay inside the cluster
Drift (manual edits)Unnoticed until the next deployDetected, and undone if selfHeal is on
RollbackRe-run an old pipelinegit revert
Audit trailPipeline logsGit history and pull request reviews
Many clustersOne pipeline step per clusterEach cluster pulls for itself (ApplicationSets)

How it fits together

A common setup uses two repositories. The app repo holds code, and its CI builds and pushes an image. The config repo holds the Kubernetes manifests. CI's last step is a commit that bumps the image tag. CI never needs cluster credentials.

Argo CD watches the config repo and syncs. If the manifest is an Argo Rollouts Rollout, the sync starts a canary or blue-green rollout. GitOps decides what should run, and the rollout strategy decides how it gets there.

Across many clusters, an ApplicationSet generates one Application per cluster. With progressive syncs it can roll out ring by ring.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: shop
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/example/shop-deploy
    targetRevision: main
    path: k8s/overlays/production
  destination:
    server: https://kubernetes.default.svc
    namespace: shop
  syncPolicy:
    automated:
      prune: true       # delete what was removed from Git
      selfHeal: true    # undo manual changes in the cluster
    syncOptions:
      - CreateNamespace=true

Gotchas