Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 38 ยท Helm in CI/CD

GitOps with Argo CD and Flux

Deploy Helm charts declaratively with GitOps: Argo CD Applications and Flux HelmReleases, how they render charts, drift correction and promotion, with a reconcile-loop stand-in.

Pushing releases from a CI job works, but the cluster's real state is then whatever the last pipeline run left behind. GitOps flips the model: a Git repository describes the desired state, and a controller inside the cluster continuously makes reality match it. Two controllers dominate: Argo CD and Flux. Both understand Helm charts natively.

flowchart LR
    Dev["Developer"] -->|pull request| Git["Git: values + chart version"]
    Git -->|watched by| Ctl["Controller<br/>(Argo CD / Flux)"]
    Ctl -->|renders chart, applies| K["Kubernetes cluster"]
    K -->|drift detected| Ctl

The controller pulls from Git; nobody pushes to the cluster.

What changes compared to helm upgrade

  • The source of truth is Git: chart reference, version and values files.
  • A reconcile loop re-applies the desired state, so manual kubectl edit changes are reverted (or at least flagged).
  • Rollback is git revert.
  • Credentials for the cluster never leave the cluster; CI needs no cluster access.

One surprise: with both tools, helm list may show little or nothing useful. Argo CD renders the chart with helm template and applies the manifests itself, so no Helm release object exists. Flux's helm-controller does run real Helm operations and does create release Secrets. Know which one you use before you debug.

Argo CD

An Argo CD Application points at a chart and supplies values:

YAML
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: shop-prod
  namespace: argocd
spec:
  project: default
  source:
    repoURL: ghcr.io/my-org/charts
    chart: webapp
    targetRevision: 0.4.0
    helm:
      releaseName: shop
      valueFiles:
        - values-prod.yaml
      parameters:
        - name: image.tag
          value: "9c0ffee"
  destination:
    server: https://kubernetes.default.svc
    namespace: prod
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true

prune: true deletes objects removed from Git; selfHeal: true reverts manual changes. For a chart that lives in the Git repository itself, set path: and repoURL: to that repository instead of chart:. Helm hooks map to Argo CD resource hooks (PreSync, PostSync), so migrations still run before the sync.

Flux

Flux uses two resources: a source describing where the chart is, and a HelmRelease describing how to install it:

YAML
apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata:
  name: webapp
  namespace: flux-system
spec:
  interval: 5m
  url: oci://ghcr.io/my-org/charts/webapp
  ref:
    semver: ">=0.4.0 <0.5.0"
---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: shop
  namespace: prod
spec:
  interval: 10m
  chartRef:
    kind: OCIRepository
    name: webapp
    namespace: flux-system
  values:
    replicaCount: 3
    image:
      tag: "9c0ffee"
  upgrade:
    remediation:
      retries: 3
  rollback:
    cleanupOnFail: true

Flux watches the source, picks the newest matching version, and runs install, upgrade, test and rollback through Helm. valuesFrom lets the release read values from ConfigMaps and Secrets, which is where encrypted secrets (SOPS) usually come in.

The reconcile loop (stand-in)

The heart of both tools is a loop: read desired state, read live state, compute a difference, act. The stand-in below plays it out for a small cluster with one manual change.

Python Stand-in: a GitOps reconcile loop

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Promotion between environments

With GitOps, promotion is a Git change. A typical layout:

TEXT
deploy/
  base/            # chart reference shared by all
  envs/
    dev/values.yaml      # chart: floating pre-release
    staging/values.yaml  # chart: 0.4.0-rc.1
    prod/values.yaml     # chart: 0.4.0 (pinned)

CI publishes a new chart or image, then opens a pull request that changes only the version line in dev. After tests pass it is copied to staging, then prod. Tools such as Flux's image automation or Argo CD Image Updater can write the new tag back to Git for you. The audit log is your Git history.

Python Stand-in: promote a version through environments

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Choosing between them

Concern Argo CD Flux
Interface Rich web UI, CLI CLI and Kubernetes events, optional UIs
Helm execution Renders with helm template, applies manifests Runs real Helm releases
Helm hooks / tests Mapped to sync hooks Native Helm behavior
Multi-cluster Strong, one control plane Per-cluster controllers

Both are sound; choose by team habit. Whichever you pick, avoid running helm upgrade by hand on a GitOps-managed release: the controller will overwrite it, or fight with it.

Pitfalls

  • Secrets in Git. Use SOPS, Sealed Secrets or an external secrets operator.
  • Floating versions in prod. Pin exact chart versions; use ranges only in dev.
  • Ignoring fields mutated by other controllers (such as replicas managed by an autoscaler). Configure ignoreDifferences in Argo CD or the equivalent in Flux to avoid endless reconciliation.
  • Treating "synced" as "healthy". Check readiness and alerts too.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where does the desired state live in GitOps?

    Git is the source of truth; the controller reconciles the cluster to it.
  2. 2. How does Argo CD usually deploy a Helm chart?

    That is why there is typically no Helm release Secret for Argo CD managed apps.
  3. 3. What does selfHeal: true do?

    Self-heal re-applies the Git state when live resources drift.
  4. 4. In GitOps, how do you roll back a bad release?

    Reverting the commit restores the desired state, and the controller applies it.

Summary

  • GitOps controllers pull chart version and values from Git and continuously reconcile the cluster.
  • Argo CD renders charts and applies manifests; Flux runs real Helm releases through HelmRelease.
  • Promotion and rollback are Git changes; keep secrets encrypted and prod versions pinned.

Next: Upgrades, Rollbacks and Release Strategies