Flux CD
A comprehensive guide to Flux CD covering GitOps, automated sync, image automation, Helm integration, and practical implementation strategies for Kubernetes.
Flux CD is a CNCF Graduated open-source GitOps tool for Kubernetes. It keeps Kubernetes clusters in sync with configuration sources like Git repositories, automatically applying changes when new code is available [citation:4][citation:10].
Flux CD is built on Kubernetes' API extension system and uses custom resources (GitRepository, Kustomization, HelmRelease) rather than a standalone REST API [citation:12]. Its key principles [citation:4]:
- Declarative Configuration: Everything is defined as code in Git
- Automated Reconciliation: Flux continuously syncs the cluster with Git
- Pull Model: Flux pulls changes from Git, minimizing attack surface [citation:4]
- Multi-Tenancy: True Kubernetes RBAC via impersonation [citation:4]
- Progressive Delivery: Canary and blue-green via Flagger [citation:4]
Flux CD consists of a set of specialized controllers that work together to enable GitOps [citation:4][citation:7][citation:10]:
Source Controller
Kustomize Controller
Helm Controller
Notification Controller
Image Automation Controllers
Flux CD is installed using the flux CLI tool, which bootstraps the cluster and configures Flux to manage itself from a Git repository [citation:7][citation:11].
# Install Flux CLI
curl -s https://fluxcd.io/install.sh | sudo bash
flux --version
# Bootstrap Flux (GitHub example)
export GITHUB_TOKEN=<your-token>
flux bootstrap github \
--owner=<your-org> \
--repository=<your-repo> \
--branch=main \
--path=./clusters/production \
--personal
# Bootstrap Flux (GitLab example)
export GITLAB_TOKEN=<your-token>
flux bootstrap gitlab \
--owner=<your-org> \
--repository=<your-repo> \
--branch=main \
--path=./clusters/production
# Verify installation
flux check
kubectl get pods -n flux-system
# Install specific components
flux install --components="source-controller,kustomize-controller,helm-controller"
- Flux requires a Git personal access token with repo permissions
- The bootstrap process creates a
flux-systemnamespace and resources - Flux supports air-gapped installations out of the box [citation:7]
- Installation is lightweight compared to ArgoCD [citation:9]
Flux CD uses GitRepository to define the source and Kustomization to define the action [citation:2][citation:7][citation:8].
# GitRepository - defines source
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: my-app
namespace: flux-system
spec:
interval: 1m
url: https://github.com/myorg/my-app
ref:
branch: main
secretRef:
name: git-credentials # Optional for private repos
# Kustomization - defines sync behavior
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: my-app
namespace: flux-system
spec:
interval: 5m
path: ./kubernetes/overlays/production
prune: true
sourceRef:
kind: GitRepository
name: my-app
targetNamespace: production
validation: client
# Multiple Kustomizations with dependencies
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: infrastructure
namespace: flux-system
spec:
interval: 5m
path: ./infrastructure
prune: true
sourceRef:
kind: GitRepository
name: infra-repo
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: applications
namespace: flux-system
spec:
interval: 5m
path: ./applications
prune: true
sourceRef:
kind: GitRepository
name: apps-repo
dependsOn:
- name: infrastructure
GitRepository defines where manifests come from, and a Kustomization defines how they are applied. This provides more flexibility than ArgoCD's single Application resource [citation:2].
Flux CD's Helm Controller manages Helm releases declaratively. It supports server-side Helm templating and full release lifecycle management [citation:2][citation:4][citation:7].
# HelmRepository
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: bitnami
namespace: flux-system
spec:
interval: 1h
url: https://charts.bitnami.com/bitnami
# HelmRelease
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: nginx
namespace: default
spec:
interval: 5m
chart:
spec:
chart: nginx
sourceRef:
kind: HelmRepository
name: bitnami
namespace: flux-system
interval: 1h
values:
replicaCount: 3
service:
type: ClusterIP
resources:
requests:
memory: "64Mi"
cpu: "250m"
# HelmRelease with values from Git
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: my-app
namespace: default
spec:
interval: 5m
chart:
spec:
chart: ./charts/my-app
sourceRef:
kind: GitRepository
name: my-app
namespace: flux-system
valuesFrom:
- kind: ConfigMap
name: app-values
valuesKey: values.yaml
# Upgrade with rollback
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: my-app
spec:
install:
remediation:
retries: 3
upgrade:
remediation:
retries: 3
rollback:
enable: true
- Server-side templating (unlike ArgoCD's client-side) [citation:2]
- Full Helm release lifecycle management
- Supports Helm hooks and tests [citation:10]
- Works with OCI registries for Helm charts [citation:4]
Flux CD provides built-in image automation that automatically updates Git manifests when new container images are available [citation:4][citation:9].
# ImageRepository - scans registry for new images
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImageRepository
metadata:
name: my-app
namespace: flux-system
spec:
image: ghcr.io/myorg/myapp
interval: 5m
accessFrom:
namespaceSelectors:
- matchLabels:
kubernetes.io/metadata.name: flux-system
# ImagePolicy - defines update policy
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImagePolicy
metadata:
name: my-app
namespace: flux-system
spec:
imageRepositoryRef:
name: my-app
filterTags:
pattern: '^v(?P.*)$'
extract: '$version'
policy:
semver:
range: '>=1.0.0 <2.0.0'
# ImageUpdateAutomation - updates Git manifests
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImageUpdateAutomation
metadata:
name: my-app
namespace: flux-system
spec:
sourceRef:
kind: GitRepository
name: my-app
gitSpec:
commit:
author:
email: flux@example.com
name: flux-bot
messageTemplate: 'Update image to {{ .NewImage }}'
push:
branch: main
update:
path: ./kubernetes/overlays/production
strategy: Setters
# Use in Kustomization with image tag
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: my-app
spec:
images:
- name: ghcr.io/myorg/myapp
newName: ghcr.io/myorg/myapp
newTag: v1.2.3 # Automatically updated by flux
- Native image automation without external tools [citation:9]
- Supports semver version ranges
- Automatically commits and pushes changes to Git
- Works with any OCI-compliant registry [citation:4]
Flux CD integrates with Flagger for progressive delivery strategies: canary, blue-green, and A/B testing [citation:4][citation:10].
# Flagger Canary
apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: my-app
namespace: default
spec:
provider: istio
targetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
progressDeadlineSeconds: 60
service:
port: 80
analysis:
interval: 30s
threshold: 5
maxWeight: 50
stepWeight: 10
metrics:
- name: request-success-rate
threshold: 99
interval: 1m
- name: request-duration
threshold: 500
interval: 1m
- Canary, blue-green, and A/B testing [citation:10]
- Metric-based analysis and rollback
- Integration with Istio, NGINX, and other traffic routers
- Works seamlessly with Flux CD
Flux CD supports multi-tenancy through native Kubernetes RBAC, where each tenant operates within their namespace using their own ServiceAccount [citation:3][citation:4].
# Tenant Namespace
apiVersion: v1
kind: Namespace
metadata:
name: tenant-a
# Tenant ServiceAccount
apiVersion: v1
kind: ServiceAccount
metadata:
name: tenant-a-sa
namespace: tenant-a
# Tenant Role (within namespace)
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: tenant-a-role
namespace: tenant-a
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
# Tenant RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: tenant-a-binding
namespace: tenant-a
subjects:
- kind: ServiceAccount
name: tenant-a-sa
namespace: tenant-a
roleRef:
kind: Role
name: tenant-a-role
apiGroup: rbac.authorization.k8s.io
# Flux GitRepository with tenant ServiceAccount
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: tenant-a-repo
namespace: tenant-a
spec:
interval: 1m
url: https://github.com/tenant-a/repo
ref:
branch: main
serviceAccountName: tenant-a-sa
- Flux uses Kubernetes RBAC via impersonation [citation:3]
- Each tenant operates within their namespace scope [citation:3]
- Blast radius is naturally bounded to the tenant scope [citation:3]
- Requires more configuration than ArgoCD's centralized approach [citation:7]
| Feature | Flux CD | ArgoCD |
|---|---|---|
| Architecture | Modular controllers | Centralized controller |
| User Interface | CLI only (third-party UIs available) [citation:2] | Full web UI [citation:2] |
| Installation | Lightweight, CLI bootstrap [citation:7] | Single YAML, heavier [citation:11] |
| Helm Templating | Server-side [citation:2] | Client-side [citation:2] |
| Image Automation | Built-in [citation:9] | External Image Updater [citation:9] |
| Multi-Tenancy | Kubernetes RBAC impersonation [citation:3] | Projects + RBAC [citation:7] |
| Multi-Cluster | Per-cluster installation [citation:2] | Centralized [citation:2] |
| Progressive Delivery | Flagger [citation:10] | Argo Rollouts [citation:7] |
| Secret Management | SOPS native integration [citation:11] | External Secrets Operator [citation:3] |
| Learning Curve | Low [citation:2] | Medium [citation:2] |
| Market Share | 11% (CNCF 2025) [citation:2] | 60% (CNCF 2025) [citation:2] |
| Best For | Security-first, Kubernetes purists [citation:9] | Teams wanting visibility and UI [citation:9] |
- You prefer a pure declarative, YAML-first approach [citation:2]
- Security and minimal attack surface are critical [citation:9]
- You need native image automation [citation:9]
- You're operating in an air-gapped environment [citation:7]
- You have strict multi-tenancy requirements [citation:3]
flux-system directory in the repo where all Flux configuration is stored [citation:7].Flux CD is a powerful, security-focused GitOps tool for Kubernetes. Its modular architecture, native image automation, and Helm integration make it an excellent choice for teams prioritizing security and declarative operations.