Skip to content
kix /docs
Install the CLI

How-to guide Author packages and clusters

Reuse one package for multiple instances

Create independently configured instances from one local or catalogue package.

An instance is one configured use of a package. Reuse the same package value when you need several copies of a workload with different names, namespaces, or settings.

Assign the same package to more than one entry under instances:

how-to/application/cluster.nix
instances.how-to-app = {
preview = {
package = webPackage;
config = {
message = "Hello from preview";
environment = "preview";
};
};
production = {
package = webPackage;
config = {
message = "Hello from production";
environment = "production";
replicas = 2;
healthCheck = {
enabled = true;
retryFor = 60;
};
};
};
};

View source on GitHub ↗

Kix evaluates the package separately for preview and production. Each evaluation receives its own:

  • scope.instanceName and namespace.
  • Evaluated config values.
  • self fixpoint containing that instance’s resources.
  • Dependency bindings.

The package can therefore name resources from scope.instanceName without the two instances colliding.

Defaults belong in the package options. Instance configuration should contain the values that differ for that deployment.

In the example, preview uses the default replica count and leaves the health check disabled. production uses two replicas and enables its post-deploy probe. Both instances still share the package’s image, resources, mounts, and resource construction.

You can place instances in different namespaces as well:

cluster.nix
instances.preview.web = {
package = webPackage;
config.environment = "preview";
};
instances.production.web = {
package = webPackage;
config.environment = "production";
};

Declare both namespaces under namespaces and wire any cross-namespace dependencies explicitly.

List the packages in the example cluster:

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

Use inspect to see the resources each instance rendered. It prints the total number of resources, the namespaces, counts by kind, and a resource inventory grouped by namespace.

kix-examples/ offline capture
❱ kix inspect how-to-application
Show outputHide output · 40 lines
Cluster: how-to-application
Total resources: 17

Namespaces (3):
  (cluster-scoped) (5 resources)
  how-to-app (10 resources)
  kube-system (2 resources)

Resource kinds:
 Kind                      Count 
 PackageInstance           4     
 ConfigMap                 3     
 CustomResourceDefinition  2     
 Deployment                2     
 Namespace                 2     
 Service                   2     
 Activation                1     
 Job                       1     

Resources:
  (cluster-scoped):
    Activation/how-to-application-pwzvpn447s7d
    CustomResourceDefinition/activations.kix.run
    CustomResourceDefinition/packageinstances.kix.run
    Namespace/how-to-app
    Namespace/kube-system
  how-to-app:
    ConfigMap/preview
    ConfigMap/production
    ConfigMap/production-health-script
    Deployment/preview
    Deployment/production
    Job/production-health
    PackageInstance/preview
    PackageInstance/production
    Service/preview
    Service/production
  kube-system:
    PackageInstance/platform-dns
    PackageInstance/platform-storage

Each instance appears under its own name with its own resources. To inspect the dependencies between them, use kix graph; inspect does not report dependency edges.

Changes to one instance’s configuration affect that instance’s rendered resources. They do not create a second copy of the package source.