Skip to content
Install the CLI

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.

The local application scenario targets kind:

how-to/application/cluster.nix
kix.flavors.kind

View source on GitHub ↗

Use 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.

Later modules can refine values supplied by the flavor:

cluster.nix
modules = [
kix.flavors.kind
{
# The kind flavor binds the CNI role exclusively to kindnet. Release it
# when the kind cluster was created with its default CNI disabled.
cluster.roles.cni = {
binding = "absent";
provider = null;
};
networkPolicy.enable = false;
namespaces.apps = { };
}
];

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.

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:

clusters/dev.nix
{ kix, packages }:
kix.buildCluster {
# Modules receive `ref` and a minimal `kix` by default. Forward the full
# `kix` and the package catalogue so shared modules can use them.
specialArgs = { inherit kix packages; };
modules = [
kix.flavors.kind
./base.nix
];
}
clusters/prod.nix
{ kix, packages }:
kix.buildCluster {
specialArgs = { inherit kix packages; };
modules = [
kix.flavors.eks
./base.nix
];
}

Register both in the flake:

flake.nix
clusters = {
dev = ./clusters/dev.nix;
prod = ./clusters/prod.nix;
};

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.

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:

clusters/test-cloud-identity-layout/external-dns.nix
# clusters/test-cloud-identity-layout/external-dns.nix: the external-dns
# instance both clusters run. It names the DNS provider, which is the
# software's own setting, and no credential: each cluster file gives
# `deps.providerCredentials` its own value.
{ packages, ... }:
{
instances.external-dns.route53 = {
package = packages.experimental.external-dns;
config = {
provider = "aws";
policy = "upsert-only";
txtOwnerId = "cloud-identity-layout/route53";
extraArgs = [ "--domain-filter=example.com" ];
};
};
}

View source on GitHub ↗

On EKS, pass an IAM role to deps.providerCredentials:

clusters/test-cloud-identity-layout/eks.nix
kix.buildCluster {
name = "cloud-identity-layout-eks";
specialArgs = { inherit packages; };
modules = [
kix.flavors.eks
./external-dns.nix
{
instances.external-dns.route53.deps.providerCredentials = kix.cloudIdentity.aws {
roleArn = "arn:aws:iam::111122223333:role/external-dns";
};
}
];
}

View source on GitHub ↗

On kind, where pods have no cloud identity, pass a Secret instance instead:

clusters/test-cloud-identity-layout/kind.nix
kix.buildCluster {
name = "cloud-identity-layout-kind";
specialArgs = { inherit packages; };
modules = [
kix.flavors.kind
./external-dns.nix
(
{ ref, ... }:
{
# A Secret with the keys AWS_ACCESS_KEY_ID,
# AWS_SECRET_ACCESS_KEY, and AWS_REGION.
instances.external-dns.aws-keys = {
package = packages.secret-ref;
config.keys = [
"AWS_ACCESS_KEY_ID"
"AWS_SECRET_ACCESS_KEY"
"AWS_REGION"
];
};
instances.external-dns.route53.deps.providerCredentials = ref.external-dns.aws-keys;
}
)
];
}

View source on GitHub ↗

See Cloud identities for supported cloud identity constructors and options.

Run check after selecting or changing a flavor:

kix-examples/
❱ 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-examples/
❱ 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]