Skip to content

FluxCD — Commands & Recipes

Bootstrap

# Install Flux CLI
curl -s https://fluxcd.io/install.sh | sudo bash

# Bootstrap with GitHub
flux bootstrap github \
  --owner=my-org \
  --repository=fleet-infra \
  --branch=main \
  --path=clusters/production \
  --personal

# Check status
flux check
flux get all

Source Management

# Add Git source
flux create source git myapp \
  --url=https://github.com/org/myapp \
  --branch=main \
  --interval=1m

# Add Helm repo
flux create source helm bitnami \
  --url=https://charts.bitnami.com/bitnami \
  --interval=10m

# Add OCI repo
flux create source oci myapp-oci \
  --url=oci://ghcr.io/org/myapp-manifests \
  --tag=latest

Kustomization

# Apply Kustomization
flux create kustomization myapp \
  --source=GitRepository/myapp \
  --path="./k8s/overlays/production" \
  --prune=true \
  --interval=5m \
  --health-check-timeout=3m

# Force reconcile
flux reconcile kustomization myapp --with-source

Helm Releases

# Create HelmRelease
flux create helmrelease nginx \
  --source=HelmRepository/bitnami \
  --chart=nginx \
  --target-namespace=web \
  --values=./values.yaml
# HelmRelease with values from ConfigMap
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: mydb
  namespace: flux-system
spec:
  interval: 10m
  chart:
    spec:
      chart: postgresql
      version: ">=15.0.0"
      sourceRef:
        kind: HelmRepository
        name: bitnami
  valuesFrom:
    - kind: ConfigMap
      name: mydb-values
  values:
    auth:
      postgresPassword: ${DB_PASSWORD}

Image Automation

# Image policy (semver)
apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImagePolicy
metadata:
  name: myapp
spec:
  imageRepositoryRef:
    name: myapp
  policy:
    semver:
      range: ">=1.0.0"

Debugging

# View all Flux resources
flux get all -A

# Check events
flux events --for Kustomization/myapp

# Suspend/resume reconciliation
flux suspend kustomization myapp
flux resume kustomization myapp

# Export existing Flux resources
flux export source git myapp > source.yaml

Sources