Skip to content

Quickstart

This walks you through the full round-trip: take an existing namespace, turn it into .kdef files, render it back to YAML, and deploy it.

If you don’t have a cluster handy, skip to API with sidecar which builds a deployment from scratch.

Pick a small namespace (maybe a test app — one Deployment, one Service, one Ingress).

Terminal window
kdef import --namespace my-app --output-dir k8s/

kdef reads everything in the namespace and writes idiomatic .kdef files. Open k8s/ and look around:

k8s/
├── vars.kdef
├── images.kdef
├── api.kdef # one file per deployment
├── configmaps.kdef
└── secrets.kdef # secret() references, not plaintext
Terminal window
kdef render --dir k8s/

That prints Kubernetes YAML to stdout. Redirect to a file if you want to diff against the original:

Terminal window
kdef render --dir k8s/ > /tmp/rendered.yaml
Terminal window
kdef diff --dir k8s/

This is the one you’ll run before every deploy. It’s kubectl diff-shaped output, but driven by kdef’s renderer — no drift between what you commit and what you ship.

Terminal window
# Dry run first
kdef apply --dir k8s/ --dry-run
# Then for real (server-side apply, --force-conflicts)
kdef apply --dir k8s/

If you’re using GitOps, you’d instead commit k8s/ and let Flux or ArgoCD apply it.

Open api.kdef and bump a replica count, or add an env var:

deployment "api" {
// ...
scale {
replicas = 3 // was 1
}
container "api" {
// ...
env {
APP_ENV = var.environment
DATABASE_URL = secret("db-credentials", "url")
NEW_FLAG = "true" // new
}
}
}
Terminal window
kdef diff --dir k8s/
# shows: replicas: 1 -> 3, new env var NEW_FLAG
kdef apply --dir k8s/

Create k8s/environments/production.kdef:

use_vars {
environment = "production"
image_tag = "v1.2.3"
}
override "app" "api" {
scale {
replicas = 5
}
}

Render/apply with the --env flag:

Terminal window
kdef render --dir k8s/ --env production
kdef diff --dir k8s/ --env production
kdef apply --dir k8s/ --env production