Creating Clusters with Class • ClusterClass

Creating Clusters with Class • ClusterClass

Good composition is like a suspension bridge; each line adds strength and takes none away — Robert Henri

ClusterClass is a composition of various templates that can be used to create and manage clusters, these templates are used to create Concrete Objects for the Cluster API cluster.

ClusterClassSpec is composed of five sections let’s take a look at each property in detail

Infrastructure • LocalObjectTemplate

Contains reference for InfrastructureClusterTemplate, which is the simplest of all elements in this ClusterClassSpec references, later used to create InfrastructureCluster Object.

Controlplane • ControlplaneClass

ControlplaneClass is a complex class with the ability to specify

  • Metadata — is used to specify additional labels and annotations that we want to be present on the generated Control plane object

  • LocalObjectTemplate — which is used to create ControlPlane Object

  • MachineInfrastructure — is used to specify InfrastructureMachineTemplate

  • MachineHealthCheckClass — allows users to specify MachineHealthChecks for control planes, creation of MachineHealthCheck objects is taken care of by Cluster API

  • ControlPlaneClassNamingStrategy — allows specifying an alternate ControlPlane name template

  • NodeDrainTimeOut, NodeDeletionTimeOut, and NodeVolumeDetachmTimeout are used to indicate various timeouts used during node drain and deletion.

Workers • WorkersClass

WorkersClass is a very simple class that allows specifying workers as MachineDeploymentClass and MachinePoolClass arrays. All the complexity is abstracted away by MachineDeploymentClass and MachinePoolClass .

Let’s first discuss the common properties shared by the MachineDeploymentClass and MachinePoolClass

  • Class — refers to a unique name for this particular MachineDeploymentClass or MachinePoolClass . This field should be unique in the ClusterClass namespace as MachineDeploymentClass and MachinePoolClass are referred to by these names in Cluster Topology

  • Template — allows users to specify MachineDeploymentClassTemplate and MachinePoolClassTemplate for MachineDeploymentClass and MachinePoolClass respectively. These ClassTemplates in turn contain references for Infrastructure and Bootstrap Templates which are used to create BootstrapConfig and Infrastructure machine objects.

  • MachineHealthCheckClass — allows users to specify MachineHealthChecks for workers, creation of MachineHealthCheck objects is taken care of by Cluster API

  • FailureDomain — allows users to specify an array of failure domains to spread the worker machines across

  • NamingStrategy — is used to control how the MachineDeployment and MachinePool object names should be generated

  • NodeDrainTimeOut, NodeDeletionTimeOut, and NodeVolumeDetachmTimeout are used to indicate various timeouts used during node drain and deletion

  • MinReadySeconds — minimum time for which the machine should remain ready before Cluster API considers it available and moves on to create new machines.

  • Strategy — allows user to regulate various MachineDeployment rollout options

Advanced Templating

Cluster API provides templating at multiple levels, allowing static file templates for input files using env substitution.

But what about injecting variables to Template objects for a ClusterClass at creation time?

The answer to this problem lies in ClusterClassVariable and ClusterClassPatch which allow the declaration of a variable its default value etc using Open API v3 Schema a patching strategy respectively for a Template.

Here while creating two clusters I can control the value of dnsImageRespository in my clusters. While my ClusterClass remains the same. Let’s see how this variable is defined using ClusterClassVariable and ClusterClassPatch

Variables • []ClusterClassVariable

ClusterClassVariable defines a variable schema using Open API v3 Schema a variable is used to define a variable its default value, name etc.

here dnsImageRespository is defined as required indicating that it is required to be present in Cluster Topology, with the default value being registry.k8s.io . This variable is later referenced by ClusterClassPatch to specify the patch.

Patches • []ClusterClassPatch

ClusterClassPatches are complex inputs that allow us to modify the Templates which are specified in the ClusterClass

In the example below the patch applies on KubeamdControlPlaneTemplate that sets the KubeamdControlPlaneTemplate.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.DNS.ImageRepisotry to the value of dnsImageRespository variable which is specified in Cluster Topology.

In the next section, we will look at Cluster Topology to see how we can reference these fields together.