Skip to main content
Work in Progress

You are viewing development documentation built from the latest commit on main (last tag v0.2.0-rc.2, source commit 25e1a892). APIs and features are subject to change.

Quickstart

This guide walks you through installing Kure, generating one Flux Kustomization from Go, and handing it to Flux. It stays at the level of a single Kubernetes object. To build a whole cluster (Cluster, Node, Bundle, Application) and write the repository layout to disk, continue with the cluster-to-disk example .

Installation

You need Go 1.27.4 or later, the version that Kure’s go.mod declares for v0.2.0-rc.1. With an older Go, the go command downloads that toolchain when you add Kure. Create a module and add Kure:

mkdir hello-kure && cd hello-kure
go mod init example.com/hello-kure
go get github.com/go-kure/kure@latest

Hello World: Generate a Simple Cluster Config

Create a minimal Go program that generates Kubernetes manifests. Start main.go with the package clause and imports:

package main

import (
    "os"
    "time"

    "github.com/go-kure/kure/pkg/io"
    "github.com/go-kure/kure/pkg/kubernetes/fluxcd"
    kustv1 "github.com/fluxcd/kustomize-controller/api/v1"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

and put this in func main() { ... }:

ks := fluxcd.CreateKustomization("hello-world", "flux-system")
ks.Spec.SourceRef = kustv1.CrossNamespaceSourceReference{
    Kind: "GitRepository",
    Name: "flux-system",
}
ks.Spec.Path = "./clusters/production"
ks.Spec.Interval = metav1.Duration{Duration: 5 * time.Minute}
ks.Spec.Prune = true

if err := io.Marshal(os.Stdout, ks); err != nil {
    panic(err)
}

That body is Example_quickstart in pkg/kubernetes/fluxcd, which go test runs and checks against the Example’s own // Output: comment. The output below reproduces that comment by hand; it is not generated.

Fetch the modules the program imports, then run it to see the generated YAML:

go mod tidy
go run main.go

Output:

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: hello-world
  namespace: flux-system
spec:
  interval: 5m0s
  path: ./clusters/production
  prune: true
  sourceRef:
    kind: GitRepository
    name: flux-system
status: {}

Deploy with Flux

The program prints the Kustomization to stdout. To deploy it you need a Flux installation that already watches your Git repository through a GitRepository named flux-system, and a ./clusters/production directory in that repository that holds the manifests the Kustomization should apply.

  1. Save the output into the repository Flux watches, then commit it

Save the file in the bootstrap path of your cluster, clusters/<cluster>/. That is the --path you gave to flux bootstrap. Do not use its flux-system subdirectory, because the kustomization.yaml there lists only the Flux components and Flux never applies other files in it.

go run main.go > /path/to/your-repo/clusters/<cluster>/hello-world.yaml
cd /path/to/your-repo
git add clusters/
git commit -m "Add hello-world kustomization"
git push
  1. Flux reconciles automatically

If a Flux Kustomization already applies the directory you saved the file in, Flux picks up the new Kustomization on its next sync. Check the status:

flux get kustomizations
  1. Or trigger manually

The hello-world Kustomization does not exist until Flux applies the file you pushed. First fetch the new commit, then reconcile the Flux Kustomization that applies the directory you saved the file in. In a default Flux bootstrap, both objects are named flux-system.

flux reconcile source git flux-system
flux reconcile kustomization flux-system

When flux get kustomizations lists hello-world, reconcile it directly:

flux reconcile kustomization hello-world --with-source

Next Steps

  • A whole cluster: The cluster-to-disk example builds a Cluster with Nodes, Bundles and Applications and writes the repository layout
  • Flux workflow: The Flux workflow guide covers the generated Flux resources in depth
  • Architecture: Read the Design Philosophy page for a deep dive into Kure’s design
  • Building objects: The Builder Contract page explains what a constructor does and does not set, when a Set*/Add* helper exists, and how to read the maturity table
  • Examples: The examples page lists the runnable examples and sample data
  • API Reference: See the full API at pkg.go.dev
  • Patching: The patch engine moved to go-kure/launcher in the launcher extraction (ADR-018); see that repository for current documentation