FluxCD is a GitOps operator for Kubernetes, designed to automate the deployment and management of applications. It synchronizes the state of your Kubernetes cluster with configurations stored in Git repositories. FluxCD continuously monitors these repositories for changes and automatically applies updates to the cluster, ensuring that the desired state defined in Git is always reflected in your running environment. This approach enhances consistency, auditability, and reliability in Kubernetes deployments by leveraging Git as the single source of truth. It also provides a way to roll back to previous versions in case of errors or unexpected issues.
FluxCD is the leading GitOps tool for Kubernetes, enabling teams to manage infrastructure and applications declaratively through Git. If youβre looking to automate Kubernetes deployments, improve security, and establish Git as your single source of truth, FluxCD is the solution.
What is FluxCD?
FluxCD is a CNCF graduated project that implements GitOps for Kubernetes. It continuously monitors Git repositories and container registries, automatically applying changes to your cluster to ensure the actual state matches the desired state defined in Git.
Core Principle: Your Git repository is the single source of truth. All cluster changes go through Git, providing complete audit trails, easy rollbacks, and declarative infrastructure management.
Why FluxCD?
Traditional vs. GitOps Deployment
Traditional Approach:
- Manual kubectl commands or scripts
- No audit trail of who changed what
- Difficult rollbacks
- Configuration drift over time
- Credentials scattered across CI/CD systems
FluxCD GitOps Approach:
- All changes via Git pull requests
- Complete audit trail automatically
- Easy rollbacks (git revert)
- Cluster state continuously reconciled
- No cluster credentials in CI/CD
Key Benefits
- Declarative: Define your desired state in Git, Flux makes it happen
- Automated: Continuous synchronization without manual intervention
- Secure: No cluster credentials needed outside the cluster
- Auditable: Every change tracked in Git history
- Recoverable: Disaster recovery is as simple as pointing Flux at your Git repo
Core Concepts
GitOps Toolkit Components
FluxCD v2 is built on the GitOps Toolkit, a set of composable APIs:
Source Controller
Manages Git repositories and Helm repositories as sources:
apiVersion: source.toolkit.fluxcd.io/v1kind: GitRepositorymetadata: name: podinfo namespace: flux-systemspec: interval: 1m url: https://github.com/stefanprodan/podinfo ref: branch: masterKustomize Controller
Reconciles Kustomize overlays:
apiVersion: kustomize.toolkit.fluxcd.io/v1kind: Kustomizationmetadata: name: podinfo namespace: flux-systemspec: interval: 5m path: ./kustomize prune: true sourceRef: kind: GitRepository name: podinfoHelm Controller
Manages Helm releases:
apiVersion: helm.toolkit.fluxcd.io/v2kind:HelmReleasemetadata: name: nginx namespace: defaultspec: interval: 5m chart: spec: chart: nginx version: "15.x" sourceRef: kind: HelmRepository name: bitnamiNotification Controller
Sends alerts and receives webhooks:
apiVersion: notification.toolkit.fluxcd.io/v1kind: Alertmetadata: name: on-call namespace: flux-systemspec: providerRef: name: slack eventSeverity: error eventSources: - kind: Kustomization name: '*'Image Automation Controllers
Automatically update image tags:
apiVersion: image.toolkit.fluxcd.io/v1beta2kind: ImagePolicymetadata: name: podinfo namespace: flux-systemspec: imageRepositoryRef: name: podinfo policy: semver: range: 5.0.xGetting Started with FluxCD
Prerequisites
- A Kubernetes cluster (kind, minikube, or cloud)
- kubectl configured
- A Git repository
- GitHub/GitLab personal access token
Installation
# Install Flux CLIbrew install fluxcd/tap/flux
# Check prerequisitesflux check --pre
# Bootstrap Flux on your clusterflux bootstrap github \ --owner=your-username \ --repository=fleet-infra \ --branch=main \ --path=./clusters/my-cluster \ --personalThis single command:
- Installs Flux components
- Creates a Git repository (if needed)
- Commits Flux manifests to your repo
- Configures Flux to sync from that repo
Deploy Your First Application
Create a Git repository structure:
fleet-infra/βββ clusters/β βββ my-cluster/β βββ flux-system/ # Flux components (auto-generated)β βββ apps/β βββ podinfo/β βββ namespace.yamlβ βββ deployment.yamlβ βββ service.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: podinfo namespace: podinfospec: replicas: 2 selector: matchLabels: app: podinfo template: metadata: labels: app: podinfo spec: containers: - name: podinfo image: ghcr.io/stefanprodan/podinfo:6.5.0 ports: - containerPort: 9898Create a Kustomization to deploy it:
apiVersion: kustomize.toolkit.fluxcd.io/v1kind: Kustomizationmetadata: name: apps namespace: flux-systemspec: interval: 10m path: ./apps prune: true sourceRef: kind: GitRepository name: flux-systemCommit and pushβFlux deploys automatically!
git add .git commit -m "Add podinfo application"git push
# Watch Flux deployflux get kustomizations --watchCommon Use Cases
1. Multi-Environment Management
Structure your repo for dev, staging, and prod:
fleet-infra/βββ clusters/β βββ dev/β βββ staging/β βββ production/βββ apps/ βββ podinfo/ βββ base/ βββ overlays/ βββ dev/ βββ staging/ βββ production/2. Multi-Tenancy
Use Fluxβs multi-tenancy lockdown:
apiVersion: kustomize.toolkit.fluxcd.io/v1kind: Kustomizationmetadata: name: team-a namespace: flux-systemspec: serviceAccountName: team-a path: ./teams/team-a sourceRef: kind: GitRepository name: flux-system3. Progressive Delivery with Flagger
Integrate Flagger for canary deployments:
apiVersion: flagger.app/v1beta1kind: Canarymetadata: name: podinfo namespace: podinfospec: targetRef: apiVersion: apps/v1 kind: Deployment name: podinfo service: port: 9898 analysis: interval: 1m threshold: 5 maxWeight: 50 stepWeight: 104. Image Automation
Automatically update images when new versions are pushed:
# Update deployment with new image versionsapiVersion: image.toolkit.fluxcd.io/v1beta1kind: ImageUpdateAutomationmetadata: name: podinfo namespace: flux-systemspec: git: commit: author: email: fluxcdbot@users.noreply.github.com name: fluxcdbot messageTemplate: 'Update image to {{range .Updated.Images}}{{println .}}{{end}}' interval: 1m sourceRef: kind: GitRepository name: flux-system update: path: ./apps/podinfo strategy: SettersBest Practices
Repository Structure
Option 1: Monorepo
- Single repository for all environments
- Use Kustomize overlays for environment-specific configs
- Simpler for small teams
Option 2: Repo-per-environment
- Separate repos for dev, staging, production
- Better access control
- Scales for larger organizations
Secret Management
Never commit secrets to Git! Use one of these approaches:
1. Mozilla SOPS:
# Install SOPS providerflux create secret sops my-secrets \ --namespace=flux-system \ --from-literal=token=ghp_xxx
# Encrypt with SOPSsops --encrypt --in-place secret.yaml2. External Secrets Operator:
apiVersion: external-secrets.io/v1beta1kind: ExternalSecretmetadata: name: examplespec: refreshInterval: 1h secretStoreRef: name: vault kind: SecretStore target: name: secret-to-create data: - secretKey: password remoteRef: key: secret/data/password3. Sealed Secrets:
# Encrypt a secretkubeseal < secret.yaml > sealed-secret.yaml# Commit sealed-secret.yaml to GitHealth Checks and Validation
apiVersion: kustomize.toolkit.fluxcd.io/v1kind: Kustomizationmetadata: name: appsspec: interval: 10m path: ./apps prune: true wait: true # Wait for resources to be ready timeout: 5m validation: client # Validate before applying healthChecks: - apiVersion: apps/v1 kind: Deployment name: podinfo namespace: podinfoNotifications
Stay informed about deployments:
# Send to SlackapiVersion: notification.toolkit.fluxcd.io/v1beta1kind: Providermetadata: name: slack namespace: flux-systemspec: type: slack channel: deployments secretRef: name: slack-url
---apiVersion: notification.toolkit.fluxcd.io/v1beta1kind: Alertmetadata: name: slack-info namespace: flux-systemspec: providerRef: name: slack eventSeverity: info eventSources: - kind: Kustomization name: '*' - kind: HelmRelease name: '*'FluxCD vs. ArgoCD
Both are excellent GitOps tools. Hereβs how they compare:
| Feature | FluxCD | ArgoCD |
|---|---|---|
| Architecture | Lightweight, toolkit-based | Monolithic with UI |
| UI | Optional (Weave GitOps) | Built-in, feature-rich |
| Multi-tenancy | Native support | Good support |
| Helm | HelmController | Native support |
| Image automation | Built-in | Plugin required |
| Complexity | Lower learning curve | More features, steeper curve |
| CNCF Status | Graduated | Graduated |
Choose FluxCD if:
- You prefer lightweight, composable tools
- You want built-in image automation
- Youβre comfortable with CLI/GitOps workflows
Choose ArgoCD if:
- You need a comprehensive UI for non-technical users
- You want application-centric management
- You need advanced RBAC with UI
Common Pitfalls
- Forgetting Source Interval: Set appropriate intervals for Git polling
- No Health Checks: Always configure health checks for critical apps
- Committing Secrets: Use SOPS, Sealed Secrets, or External Secrets
- Ignoring Dependencies: Use
dependsOnto order deployments - Not Using Prune: Set
prune: trueto remove deleted resources
Troubleshooting
# Check Flux statusflux check
# Get all Flux resourcesflux get all
# Describe a Kustomizationflux get kustomization apps
# View logsflux logs --all-namespaces --follow
# Suspend/Resume reconciliationflux suspend kustomization appsflux resume kustomization apps
# Force reconciliationflux reconcile kustomization apps --with-sourceLearning Path
Beginner
- Understand GitOps principles
- Install Flux on a local cluster
- Deploy your first application via Git
- Learn Kustomize basics
- Set up notifications
Intermediate
- Manage multiple environments
- Implement secret management with SOPS
- Automate image updates
- Configure health checks and dependencies
- Use Helm with Flux
Advanced
- Implement multi-tenancy
- Progressive delivery with Flagger
- Multi-cluster management
- Custom automation with Flux APIs
- Disaster recovery strategies
Conclusion
FluxCD brings the power of GitOps to Kubernetes, making deployments safer, more auditable, and fully automated. By treating Git as the single source of truth, you gain version control, peer review, and rollback capabilities for your entire infrastructure.
Start with a single application, experience the GitOps workflow, and gradually expand to manage your entire Kubernetes estate through Git.
Want to see Flux in action? Check out our hands-on videos below for real-world examples and advanced patterns.