123DevOps··5 min read

Pure GitOps: fully separating the build pipeline (CI) from state synchronization (CD) with Argo CD and Flux

Why your CI pipeline shouldn't deploy, how to structure the manifests repository, how to promote versions across environments with Pull Requests, and when to choose Argo CD or Flux.

CI/CD

On many teams, “GitOps” is still a CI pipeline whose last step runs kubectl apply or helm upgrade using a cluster-admin credential stored as a secret. It works — until someone changes something directly in the cluster, the secret leaks, or nobody can say which version is actually running in production.

Pure GitOps separates two responsibilities that usually get mixed together:

  • CI (continuous integration): compile, test, scan, and publish an immutable artifact (the container image).
  • CD (continuous delivery): make sure the cluster state matches the state declared in Git — continuously, not just at deploy time.

In our practical Argo CD guide we covered the basics. Here the focus is the full architecture.

The end-to-end flow

  1. The developer merges into the application repository.
  2. CI tests the code, builds the image, and publishes it with an immutable tag (the commit SHA) — and records the digest.
  3. CI (or an image automation bot) opens a Pull Request against the manifests repository, changing the image version for the target environment.
  4. Merging that PR is the deploy.
  5. Argo CD or Flux, running inside the cluster, detects the change and reconciles.

Notice what doesn’t exist in this flow: cluster credentials in CI. The GitOps agent pulls changes (a pull model), so the CI pipeline never needs write access to production.

Structuring the manifests repository

A simple, scalable pattern with Kustomize:

k8s-manifests/
├── apps/
│   └── api/
│       ├── base/              # shared Deployment, Service, HPA
│       └── overlays/
│           ├── dev/
│           ├── staging/
│           └── prod/          # production replicas, resources and image version
└── clusters/
    ├── staging/               # what each cluster should run
    └── prod/

Avoid one branch per environment (dev, staging, main). Merges between environment branches pile up accidental differences and make promotions hard to audit. Prefer one directory per environment on the same branch: the difference between staging and production shows up in a plain diff.

The CI step that updates the manifest

The last CI step doesn’t deploy — it proposes a change:

cd k8s-manifests/apps/api/overlays/staging
kustomize edit set image ghcr.io/your-org/api=ghcr.io/your-org/api@${DIGEST}
git checkout -b deploy/api-staging-${GITHUB_SHA::7}
git commit -am "deploy(api): staging -> ${GITHUB_SHA::7}"
git push origin HEAD
gh pr create --fill --label deploy

Pinning the image by digest (@sha256:...) guarantees nobody can swap the contents out from under a tag. For staging, the PR can be merged automatically; for production, it requires approval.

An alternative is to let the agent itself update versions: Flux has native image automation (ImageRepository, ImagePolicy, and ImageUpdateAutomation), and the Argo ecosystem has Argo CD Image Updater. Promotion tools such as Kargo orchestrate moving a version through multiple environments.

The CD side: Flux

In Flux, a Kustomization points to a directory in the repository and keeps the cluster in sync, with health checks:

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: api-prod
  namespace: flux-system
spec:
  interval: 5m
  path: ./apps/api/overlays/prod
  prune: true
  sourceRef:
    kind: GitRepository
    name: k8s-manifests
  healthChecks:
    - apiVersion: apps/v1
      kind: Deployment
      name: api
      namespace: api
  timeout: 3m

In Argo CD, the equivalent is an Application (or an ApplicationSet, to generate multiple applications from a pattern).

Argo CD or Flux?

Both are CNCF graduated projects and both solve the problem well. The differences come down to style:

Aspect Argo CD Flux
Interface Rich web UI with visual resource views and diffs CLI- and CRD-focused; third-party UIs
Model Centralized applications, a server with its own API and RBAC A set of controllers, everything as a Kubernetes resource
Helm Renders templates and applies them as manifests Installs real Helm releases (HelmRelease)
Image automation Via Argo CD Image Updater Native
Multi-cluster One Argo CD managing several clusters is common Usually one Flux per cluster
Progressive delivery Argo Rollouts Flagger

Teams that want visibility for developers and a central dashboard tend to prefer Argo CD. Platform teams that treat everything as code and want fewer central components tend to prefer Flux.

Rollback, drift, and auditing

  • Rollback is git revert. The previous state is in the history, with author, review, and reason.
  • Drift gets detected. Someone changed a resource directly in the cluster? The agent shows the difference and, with self-heal, reverts it.
  • Auditing for free. “Who put version 2.3 in production, and who approved it?” is answered by the PR.

Problems that show up in practice

  • Secrets. Never in Git as plain text. Use SOPS (which Flux decrypts natively), Sealed Secrets, or the External Secrets Operator reading from a vault.
  • Commit storms. Many services deploying frequently generate hundreds of bot commits. Batch updates or use promotion tools.
  • Developer feedback. With deploys decoupled from CI, developers lose “green pipeline = deployed.” Set up notifications (Argo CD Notifications or Flux’s Notification Controller) to the team channel and to the original commit.
  • Database migrations. Use hooks (Argo CD PreSync/Sync) or jobs versioned alongside the application, and write migrations that are backward compatible with the previous version.
  • Dependency ordering. Resources that depend on others (CRDs before the resources that use them) need sync waves in Argo CD or dependsOn in Flux.

Pure GitOps checklist

  • CI has no write credentials for any cluster
  • Images published with immutable tags and referenced by digest
  • Manifests repository with one directory per environment (not branches)
  • Promotion to production via Pull Request with approval
  • Self-heal and prune enabled, with visible drift detection
  • No plain-text secrets in Git
  • Sync notifications reaching the team

In pure GitOps, the pipeline doesn’t deploy: it proposes. Git decides, and the cluster obeys.

Get updates on new posts and stay in the loop!