How-to guide / Start and inspect a Kix project
Select and configure a cluster flavor
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
A flavor supplies cluster defaults for a Kubernetes environment. Select one near the beginning of the cluster’s module list, then place project-specific configuration after it.
Select a flavor
Section titled “Select a flavor”The local application scenario targets kind:
20 kix.flavors.kindUse the flavor matching the cluster you will deploy to. Kix includes provider profiles for local, managed, and self-hosted Kubernetes environments. The flavor can set values such as:
- Provider identity and Kubernetes assumptions.
- DNS and storage role bindings.
- Platform imports already supplied by the environment.
- Defaults for nodes, networking, and storage behavior.
A flavor is a module, so it belongs in the same modules list as the rest of
the cluster configuration.
Put overrides after the flavor
Section titled “Put overrides after the flavor”Later modules can refine values supplied by the flavor:
1modules = [2 kix.flavors.kind3
4 {5 # The kind flavor binds the CNI role exclusively to kindnet. Release it6 # when the kind cluster was created with its default CNI disabled.7 cluster.roles.cni = {8 binding = "absent";9 provider = null;10 };11
12 networkPolicy.enable = false;13 namespaces.apps = { };14 }15];Flavors set role bindings and capability flags with lib.mkDefault. A later
module can therefore override them with an ordinary assignment. Put the flavor
first so the cluster-specific choices that override it are easy to see.
Keep environment selection explicit
Section titled “Keep environment selection explicit”When a repository targets several environments, define a cluster for each one and select its flavor explicitly. Do not infer the flavor from the current kubectl context. Evaluation should produce the same manifests without contacting a cluster.
Put everything the environments share in a module they both import:
1{ kix, packages }:2
3kix.buildCluster {4 # Modules receive `ref` and a minimal `kix` by default. Forward the full5 # `kix` and the package catalogue so shared modules can use them.6 specialArgs = { inherit kix packages; };7 modules = [8 kix.flavors.kind9 ./base.nix10 ];11}1{ kix, packages }:2
3kix.buildCluster {4 specialArgs = { inherit kix packages; };5 modules = [6 kix.flavors.eks7 ./base.nix8 ];9}Register both in the flake:
1clusters = {2 dev = ./clusters/dev.nix;3 prod = ./clusters/prod.nix;4};mkFlake passes only kix, packages, and pins to a cluster function. If
the function requires another argument, such as an externally supplied
flavor, evaluation fails with called without required argument.
Keep credentials in the cluster file
Section titled “Keep credentials in the cluster file”A workload that calls a cloud API can use a cloud identity on one cluster and a
Secret on another. Put deps.providerCredentials in each cluster file so both
clusters can share the workload definition:
2# clusters/test-cloud-identity-layout/external-dns.nix: the external-dns3# instance both clusters run. It names the DNS provider, which is the4# software's own setting, and no credential: each cluster file gives5# `deps.providerCredentials` its own value.6{ packages, ... }:7{8 instances.external-dns.route53 = {9 package = packages.experimental.external-dns;10 config = {11 provider = "aws";12 policy = "upsert-only";13 txtOwnerId = "cloud-identity-layout/route53";14 extraArgs = [ "--domain-filter=example.com" ];15 };16 };17}On EKS, pass an IAM role to deps.providerCredentials:
10kix.buildCluster {11 name = "cloud-identity-layout-eks";12 specialArgs = { inherit packages; };13 modules = [14 kix.flavors.eks15 ./external-dns.nix16 {17 instances.external-dns.route53.deps.providerCredentials = kix.cloudIdentity.aws {18 roleArn = "arn:aws:iam::111122223333:role/external-dns";19 };20 }21 ];22}On kind, where pods have no cloud identity, pass a Secret instance instead:
9kix.buildCluster {10 name = "cloud-identity-layout-kind";11 specialArgs = { inherit packages; };12 modules = [13 kix.flavors.kind14 ./external-dns.nix15 (16 { ref, ... }:17 {18 # A Secret with the keys AWS_ACCESS_KEY_ID,19 # AWS_SECRET_ACCESS_KEY, and AWS_REGION.20 instances.external-dns.aws-keys = {21 package = packages.secret-ref;22 config.keys = [23 "AWS_ACCESS_KEY_ID"24 "AWS_SECRET_ACCESS_KEY"25 "AWS_REGION"26 ];27 };28 instances.external-dns.route53.deps.providerCredentials = ref.external-dns.aws-keys;29 }30 )31 ];32}See Cloud identities for supported cloud identity constructors and options.
Check the result
Section titled “Check the result”Run check after selecting or changing a flavor:
❱ kix check how-to-application
TOOL RESULT DETAILS
eval pass 15 manifests evaluated
scorecard pass 0 errors, 11 warnings, 2 info
governance.hasOwner (warning), 2:
how-to-app/preview: package 'preview' has no meta.owner
how-to-app/production: package 'production' has no meta.owner
reliability.boundedResources (warning), 2:
how-to-app/preview/preview: container 'nginx' is missing resource settings: limits.cpu. Set CPU and memory requests and limits.
how-to-app/production/production: container 'nginx' is missing resource settings: limits.cpu. Set CPU and memory requests and limits.
reliability.hasProbes (warning), 2:
how-to-app/preview/preview: container 'nginx' has no livenessProbe
how-to-app/production/production: container 'nginx' has no livenessProbe
security.hasNetworkPolicy (warning), 1:
how-to-app: namespace 'how-to-app' has workloads but no network policy
security.nonRoot (warning), 2:
how-to-app/preview/preview: container 'nginx' may run as root: neither it nor the pod sets securityContext.runAsNonRoot, and no non-zero runAsUser resolves for it
how-to-app/production/production: container 'nginx' may run as root: neither it nor the pod sets securityContext.runAsNonRoot, and no non-zero runAsUser resolves for it
security.readOnlyRootfs (warning), 2:
how-to-app/preview/preview: container 'nginx' does not set readOnlyRootFilesystem
how-to-app/production/production: container 'nginx' does not set readOnlyRootFilesystem
2 info finding(s) not listed; run with -v to list them. Inspect the package list to see platform imports contributed by the flavor (platform-dns and platform-storage come from the kind flavor):
❱ kix list packages how-to-application
NAME VERSION STATUS
platform-dns - import [kube-system]
platform-storage - import [kube-system]
preview 1.0.0 installed [how-to-app]
production 1.0.0 installed [how-to-app]