Skip to content

Flux CD

kdef ships a Kubernetes controller that integrates natively with Flux CD. You define a KdefRelease CR pointing at a Flux GitRepository, and the controller handles rendering and applying on every new revision.

Terminal window
git clone https://github.com/gsid-nl/kdef.git
cd kdef
helm install kdef-controller ./flux-controller/chart \
--namespace flux-system

The controller registers the kdef.gsid.nl/v1alpha1 API group and runs in the flux-system namespace alongside Flux’s own controllers.

apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: my-app
namespace: flux-system
spec:
interval: 1m
url: https://github.com/example/my-app.git
ref:
branch: main
apiVersion: kdef.gsid.nl/v1alpha1
kind: KdefRelease
metadata:
name: my-app
namespace: flux-system
spec:
sourceRef:
kind: GitRepository
name: my-app
path: ./k8s/
interval: 5m
prune: true

That’s it. The controller will:

  1. Watch the GitRepository for new revisions
  2. Download and extract the artifact
  3. Run kdef render on the .kdef files in path
  4. Apply the rendered manifests via server-side apply
  5. Prune resources that dropped out of the output (when prune: true)

Pass --env through to the render:

spec:
env: production # loads environments/production.kdef
spec:
set:
image_tag: "v2.0.0"
replicas: "3"

For complex values (lists, maps), mount them from a ConfigMap or Secret:

spec:
valuesFrom:
kind: Secret # or ConfigMap
name: my-app-values
key: values.json # default
spec:
suspend: true

Useful during incidents or deliberate drift investigations.

Terminal window
kubectl get kdefreleases -n flux-system
# NAME READY STATUS REVISION AGE
# my-app True Applied revision: main@sha256:abc123... main@sha... 5m
FieldTypeRequiredDescription
sourceRef.kindstringyesGitRepository, OCIRepository, or Bucket
sourceRef.namestringyesName of the Flux source
sourceRef.namespacestringnoNamespace of the source (defaults to KdefRelease namespace)
pathstringnoPath within the artifact to the kdef project directory
envstringnoEnvironment name — loads environments/<env>.kdef
setmapnoVariable overrides (--set equivalent)
valuesFrom.kindstringnoConfigMap or Secret
valuesFrom.namestringnoName of the ConfigMap/Secret
valuesFrom.keystringnoKey in data (defaults to values.json)
intervaldurationyesReconciliation interval (e.g. 5m, 1h)
pruneboolnoDelete resources that dropped out of output
targetNamespacestringnoOverride namespace for all resources
serviceAccountNamestringnoServiceAccount for impersonation
suspendboolnoPause reconciliation

A multi-app repo (see Multi-app layout) deployed with one KdefRelease per environment:

---
apiVersion: kdef.gsid.nl/v1alpha1
kind: KdefRelease
metadata:
name: platform-staging
namespace: flux-system
spec:
sourceRef:
kind: GitRepository
name: platform
path: ./
env: staging
interval: 2m
prune: true
---
apiVersion: kdef.gsid.nl/v1alpha1
kind: KdefRelease
metadata:
name: platform-production
namespace: flux-system
spec:
sourceRef:
kind: GitRepository
name: platform
path: ./
env: production
interval: 5m
prune: true

Staging reconciles every 2 minutes for fast feedback. Production every 5 minutes.