Skip to content
Install the CLI

Tutorial 05

Basic graph and deploy loop

These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.

The last tutorial created a cluster from scratch. This tutorial uses that same cluster to look more closely at the Kix loop:

  1. kix check validates the evaluated cluster
  2. kix build shows the rendered resources
  3. kix plan --read-only previews against live state
  4. kix deploy applies the checked result
  5. kix graph inspects what Kix knows

The goal is not to learn every graph detail yet. The goal is to see that Kix can evaluate a cluster before it touches Kubernetes.

  • Finish the first cluster from scratch tutorial.
  • Keep the 04-from-scratch cluster entry in flake.nix.
  • Make sure the new cluster file is known to Git. New files in a Git flake are invisible to Nix until they are added to the index:
kix-examples/
❱ git ls-files --error-unmatch tutorial-04/cluster.nix

If that command fails, add the file:

kix-examples/
❱ git add tutorial-04/cluster.nix

Run the Kix checks first:

kix-examples/
❱ kix check 04-from-scratch
 TOOL       RESULT  DETAILS                      
 eval       pass    9 manifests evaluated        
 scorecard  pass    0 errors, 1 warnings, 0 info 

security.hasNetworkPolicy (warning), 1:
  tutorial-04: namespace 'tutorial-04' has workloads but no network policy

This evaluates the cluster and runs validation before anything is applied to Kubernetes. For this tiny cluster, the output should be short. The important part is the habit: check the evaluated cluster before deploying it.

If Kix fails here, fix the cluster file before moving on. A failed check means the deploy step should not run yet.

Now render the cluster:

kix-examples/ offline capture
❱ kix build 04-from-scratch
Show outputHide output · 245 lines
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kix.run/depends-on: qrh908pfdb2030zrxsp8018aiinicd2w,rbh9j2l38rvz2f1q1mz0m30f2nl0ba6z
    kix.run/identity-hash: 2s337rhd38i2mi5vl0v1vimh8k1087av
    kix.run/package: hello-world
    kix.run/package-namespace: tutorial-04
  labels:
    app.kubernetes.io/instance: hello-world
    app.kubernetes.io/managed-by: kix
    app.kubernetes.io/name: hello-world
  name: hello-world
  namespace: tutorial-04
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/instance: hello-world
      app.kubernetes.io/name: hello-world
  template:
    metadata:
      annotations:
        checksum/config: 09a5f5226eb7f1d6e3714cfdc9e2e25cb53bc678f75420600fc4ec7af387e552
      labels:
        app.kubernetes.io/instance: hello-world
        app.kubernetes.io/name: hello-world
    spec:
      containers:
      - image: docker.io/nginxinc/nginx-unprivileged:1.30.6-alpine@sha256:f5116ed4606f3eb015dd4a8e28cb9b351476dc0ad4bc6e9f93b19cec130cdf03
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 8080
          periodSeconds: 10
        name: nginx
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        readinessProbe:
          failureThreshold: 1
          httpGet:
            path: /healthz
            port: 8080
          periodSeconds: 5
        resources:
          limits:
            cpu: 100m
            memory: 64Mi
          requests:
            cpu: 50m
            memory: 32Mi
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          seccompProfile:
            type: RuntimeDefault
        volumeMounts:
        - mountPath: /etc/nginx/conf.d
          name: config
          readOnly: true
        - mountPath: /tmp
          name: tmp
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          name: hello-world
        name: config
      - emptyDir: {}
        name: tmp
---
apiVersion: kix.run/v1alpha1
kind: Activation
metadata:
  annotations:
    kix.run/built-via: /nix/store/546imrfzawl2bknsm7arrvaj03x175r6-kix-activation-04-from-scratch.json
    kix.run/depends-on: 2cmj19b6sfr4vfl5brcfdgkl4rxfj2sm,4sq8laq4iq1acp2kfbc1jidw8h96hb2a,mkgdf3yajj0a92l7fspcy7ciykw4dsl1
    kix.run/identity-hash: 36l8ch2yrs3bcjkbvrhkvg4dv27h48f3
    kix.run/package: _cluster
    kix.run/package-namespace: _cluster
  labels:
    app.kubernetes.io/managed-by: kix
    kix.run/cluster: 04-from-scratch
  name: 04-from-scratch-36l8ch2yrs3b
spec:
  instances:
    kube-system:
      platform-dns: platform-dns
      platform-storage: platform-storage
    tutorial-04:
      hello-world: hello-world
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
  annotations:
    kix.run/depends-on: sj0fv5bs2hnh9zcqdh62ph34l2wm0b1m
    kix.run/identity-hash: mkgdf3yajj0a92l7fspcy7ciykw4dsl1
    kix.run/import-apiversion: v1
    kix.run/import-fqdn: kube-dns.kube-system.svc.cluster.local
    kix.run/import-kind: Service
    kix.run/import-name: kube-dns
    kix.run/mode: import
    kix.run/package: _cluster
    kix.run/package-namespace: _cluster
  labels:
    app.kubernetes.io/instance: platform-dns
    app.kubernetes.io/managed-by: kix
  name: platform-dns
  namespace: kube-system
spec:
  instanceName: platform-dns
  mode: import
  namespaceName: kube-system
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
  annotations:
    kix.run/depends-on: sj0fv5bs2hnh9zcqdh62ph34l2wm0b1m
    kix.run/identity-hash: 4sq8laq4iq1acp2kfbc1jidw8h96hb2a
    kix.run/import-apiversion: storage.k8s.io/v1
    kix.run/import-kind: StorageClass
    kix.run/import-name: standard
    kix.run/mode: import
    kix.run/package: _cluster
    kix.run/package-namespace: _cluster
  labels:
    app.kubernetes.io/instance: platform-storage
    app.kubernetes.io/managed-by: kix
  name: platform-storage
  namespace: kube-system
spec:
  instanceName: platform-storage
  mode: import
  namespaceName: kube-system
---
apiVersion: kix.run/v1alpha1
kind: PackageInstance
metadata:
  annotations:
    kix.run/depends-on: hjinzvk0rvpk41zksl3678vvbmx3yndc,qrh908pfdb2030zrxsp8018aiinicd2w
    kix.run/identity-hash: 2cmj19b6sfr4vfl5brcfdgkl4rxfj2sm
    kix.run/package: _cluster
    kix.run/package-namespace: _cluster
    kix.run/root: hello-world
  labels:
    app.kubernetes.io/instance: hello-world
    app.kubernetes.io/managed-by: kix
  name: hello-world
  namespace: tutorial-04
spec:
  instanceName: hello-world
  namespaceName: tutorial-04
  package: echo-server
  version: "1.30.6"
---
apiVersion: v1
data:
  default.conf: |
    server {
        listen 8080;
        location / {
            root /etc/nginx/conf.d;
            default_type text/plain;
            try_files /message.txt =404;
            # nginx refuses a POST for a static file with 405. The
            # redirect turns the request into a GET, so every
            # method gets the message.
            error_page 405 =200 /message.txt;
        }
        location /healthz {
            default_type text/plain;
            return 200 'ok\n';
        }
    }
  message.txt: |
    Hello from my first Kix cluster!
kind: ConfigMap
metadata:
  annotations:
    kix.run/depends-on: qrh908pfdb2030zrxsp8018aiinicd2w
    kix.run/identity-hash: rbh9j2l38rvz2f1q1mz0m30f2nl0ba6z
    kix.run/package: hello-world
    kix.run/package-namespace: tutorial-04
  labels:
    app.kubernetes.io/instance: hello-world
    app.kubernetes.io/managed-by: kix
  name: hello-world
  namespace: tutorial-04
---
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kix.run/identity-hash: sj0fv5bs2hnh9zcqdh62ph34l2wm0b1m
    kix.run/package: _cluster
    kix.run/package-namespace: _cluster
  labels:
    app.kubernetes.io/managed-by: kix
    kubernetes.io/metadata.name: kube-system
  name: kube-system
---
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kix.run/identity-hash: qrh908pfdb2030zrxsp8018aiinicd2w
    kix.run/package: _cluster
    kix.run/package-namespace: _cluster
  labels:
    app.kubernetes.io/managed-by: kix
    kubernetes.io/metadata.name: tutorial-04
  name: tutorial-04
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    kix.run/depends-on: 2s337rhd38i2mi5vl0v1vimh8k1087av,qrh908pfdb2030zrxsp8018aiinicd2w
    kix.run/identity-hash: hjinzvk0rvpk41zksl3678vvbmx3yndc
    kix.run/package: hello-world
    kix.run/package-namespace: tutorial-04
  labels:
    app.kubernetes.io/instance: hello-world
    app.kubernetes.io/managed-by: kix
  name: hello-world
  namespace: tutorial-04
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app.kubernetes.io/instance: hello-world
    app.kubernetes.io/name: hello-world
  type: ClusterIP

This prints the Kubernetes resources Kix built from your cluster definition. You should see familiar objects such as a Namespace, Deployment, and Service.

For now, use kix build as a window into what Kix evaluated. In normal use, you usually let kix deploy render and apply the checked result for you.

Ask Kix what is different from the live cluster:

kix-examples/ live capture
❱ kix plan 04-from-scratch --read-only
Show outputHide output · 7 lines
Connecting to context kind-kix-docs (https://127.0.0.1:39863)...
⠁ Fetching live cluster state...                                                Discovering API resources...
Fetching managed resources (62 resource types)...
⠉ Fetching live cluster state...                                                Fetched 9 resources across 62 resource types
Skipped 7 objects that belong to Kix cluster '02-hello-world'.
3 packages: 3 unchanged, 0 changed, 0 added, 0 removed
No differences found.

If your live cluster already matches the checked result, the preview should be empty or say there is nothing to change. If the hello-world cluster from the local setup tutorial is still deployed in the same kind cluster, Kix reports that it skipped its objects: kix plan --read-only compares only the Kix cluster you name.

Now make a visible edit in tutorial-04/cluster.nix:

tutorial-04/cluster.nix
config = {
message = "Preview this before deploy.";
};

Check that Git sees the edit:

kix-examples/
❱ git status --short

Because tutorial-04/cluster.nix is already tracked, Nix can see this dirty edit. You do not need to commit it.

Run the preview again:

kix-examples/ live capture
❱ kix plan 04-from-scratch --read-only
Show outputHide output · 28 lines
Connecting to context kind-kix-docs (https://127.0.0.1:39863)...
⠁ Fetching live cluster state...                                                Discovering API resources...
Fetching managed resources (62 resource types)...
Fetched 9 resources across 62 resource types
Skipped 7 objects that belong to Kix cluster '02-hello-world'.
3 packages: 2 unchanged, 1 changed, 0 added, 0 removed

  tutorial-04
    ~ hello-world 1.30.6 (2 changed, 2 tracking annotation only)
      ~ ConfigMap/hello-world@tutorial-04
          ~ $.data.message.txt:
              --- old
              +++ new
              @@ -1 +1 @@
              -Hello from my first Kix cluster!
              +Preview this before deploy.
      ~ Deployment.apps/hello-world@tutorial-04
          ~ $.spec.template.metadata.annotations.checksum/config:
              old: "(hash, not shown)"
              new: "(hash, changed, not shown)"
      ~ PackageInstance.kix.run/hello-world@tutorial-04 (tracking annotation only; no spec change or restart)
      ~ Service/hello-world@tutorial-04 (tracking annotation only; no spec change or restart)

  Activation: 04-from-scratch-36l8ch2yrs3b -> 04-from-scratch-sr9n3106hcxd


Made by a read-only comparison with the cluster. Not checked: admission webhooks, admission policies, field ownership conflicts, and invalid objects; `kix plan` checks them.
(exit code: 2)

This time Kix should show the change before it applies anything. That is the basic preview loop: edit locally, evaluate locally, inspect the change, then deploy.

Deploy the change:

kix-examples/ live capture
❱ kix deploy 04-from-scratch -y
Show outputHide output · 29 lines
Building cluster '04-from-scratch'...
Cluster 04-from-scratch: 9 manifests
Connecting to context kind-kix-docs (https://127.0.0.1:39863)...
Current deployment: 04-from-scratch-36l8ch2yrs3b (build 36l8ch2y...)

  tutorial-04
    ~ hello-world 1.30.6 (2 changed, 2 tracking annotation only)

  Plan: 1 updated, 2 unchanged
  Resources: 2 changed in content, 2 tracking annotation only (no spec change or restart)

Not checked by any preview: whether Pods start, pull their images, and pass their readiness probes.

Objects: 5 to write, 0 to delete (sha256:80b409aef921f44b529b00099fc59fb2e13489693966033f70d5e3e184ad3195)
plan: 9 nodes
  ~ ConfigMap/hello-world@tutorial-04 configured
  ✔ ConfigMap/hello-world@tutorial-04 ready
  ~ Deployment.apps/hello-world@tutorial-04 configured
  ✔ Deployment.apps/hello-world@tutorial-04 ready
  ~ Service/hello-world@tutorial-04 configured
  ✔ Service/hello-world@tutorial-04 ready
  ~ PackageInstance.kix.run/hello-world@tutorial-04 configured
  ✔ PackageInstance.kix.run/hello-world@tutorial-04 ready
  ~ Activation.kix.run/04-from-scratch-sr9n3106hcxd configured
  ✔ Activation.kix.run/04-from-scratch-sr9n3106hcxd ready
  • activation '04-from-scratch-36l8ch2yrs3b' → Superseded
  • activation '04-from-scratch-sr9n3106hcxd' → Active

Deploy complete: 0 created, 5 configured, 4 unchanged, 0 failed

Kix evaluates the cluster, computes what needs to change, and applies the checked result to Kubernetes.

Check the resource status:

kix-examples/
❱ kix status 04-from-scratch
Cluster 04-from-scratch on Kubernetes v1.35.0 (context kind-kix-docs, https://127.0.0.1:39863)
Last deploy: 04-from-scratch-sr9n3106hcxd  Active  0s ago

  kube-system/platform-dns        1 resource   ok
  kube-system/platform-storage    1 resource   ok
  tutorial-04/hello-world         4 resources  ok
  (cluster-level)                 2 resources  ok

8 resources: 8 ok.

Then port-forward and verify the response:

kix-examples/
❱ kix port-forward 04-from-scratch hello-world 8080:8080

In another terminal:

❱ curl http://localhost:8080/
Preview this before deploy.

Stop the port-forward with Ctrl-C.

Run:

kix-examples/ offline capture
❱ kix graph 04-from-scratch -o tree
Show outputHide output · 21 lines
Namespace/kube-system
├── PackageInstance.kix.run/platform-storage@kube-system (import)
│   └── Activation.kix.run/04-from-scratch-36l8ch2yrs3b
└── PackageInstance.kix.run/platform-dns@kube-system (import)
    └── Activation.kix.run/04-from-scratch-36l8ch2yrs3b
Namespace/tutorial-04
├── Service/hello-world@tutorial-04
│   └── PackageInstance.kix.run/hello-world@tutorial-04
│       └── Activation.kix.run/04-from-scratch-36l8ch2yrs3b
├── ConfigMap/hello-world@tutorial-04
│   └── Deployment.apps/hello-world@tutorial-04
│       └── Service/hello-world@tutorial-04
│           └── PackageInstance.kix.run/hello-world@tutorial-04
│               └── Activation.kix.run/04-from-scratch-36l8ch2yrs3b
├── PackageInstance.kix.run/hello-world@tutorial-04
│   └── Activation.kix.run/04-from-scratch-36l8ch2yrs3b
└── Deployment.apps/hello-world@tutorial-04
    └── Service/hello-world@tutorial-04
        └── PackageInstance.kix.run/hello-world@tutorial-04
            └── Activation.kix.run/04-from-scratch-36l8ch2yrs3b
9 resources, 12 dependencies

For this cluster the graph is still small. You may see Kix’s own activation resources, the namespace, platform imports, and the hello-world package resources. The useful habit is to read the graph as “what Kix knows about this cluster,” not as raw YAML.

Do not worry about the deeper graph mechanics yet. Later tutorials add service dependencies, cross-namespace wiring, generated network policy, and scorecard rules. Each one gives the graph more useful information.

You used the same local cluster definition through the main Kix loop:

  • kix check catches problems before deploy
  • kix build shows the rendered Kubernetes resources
  • kix plan --read-only previews changes against the live cluster
  • kix deploy applies the evaluated result
  • kix status and kix graph inspect what Kix knows afterward

The next tutorial adds the first real relationship: one local package depends on another service.