Dependency Management in Flux
What you'll learn: How to control the order in which Flux deploys resources using dependencies and health checks.
Why Deployment Order Matters
Imagine deploying a web application before its database is ready—the app would crash immediately. In Flux, not all resources should deploy simultaneously. Some components depend on others being healthy first: databases before APIs, CRDs before custom resources, or configuration before applications.
The dependsOn Field
Flux's Kustomization resources support a dependsOn array that explicitly declares prerequisites. This works like a checklist: Flux won't reconcile a Kustomization until all its dependencies are healthy and synced.
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: app-backend
namespace: flux-system
spec:
dependsOn:
- name: database
- name: shared-config
interval: 10m
path: ./backend
sourceRef:
kind: GitRepository
name: fleet-repo
Here, app-backend waits for both database and shared-config Kustomizations to be ready before deploying.
Health Checks in the Chain
Flux doesn't just wait for dependencies to exist—it waits for them to be healthy. The Source Controller and Kustomize Controller verify that dependent resources pass their readiness checks (the same health checks covered in earlier lessons). If database fails health validation, app-backend stays paused.
This creates a reliable, ordered deployment pipeline without manual intervention or complex scripting.
Use Cases
- Infrastructure first: Deploy ingress controllers before applications
- CRDs before CRs: Install custom resource definitions before resources that use them
- Config then app: Ensure ConfigMaps and Secrets exist before deployments
Key Takeaway:
Flux's dependsOn fields and automatic health checks ensure resources deploy in the correct order, preventing failures caused by missing dependencies.