Skip to content

Commit 3f82704

Browse files
committed
Add MPs to ClusterClass Documentation
1 parent b4574d4 commit 3f82704

File tree

2 files changed

+79
-15
lines changed

2 files changed

+79
-15
lines changed

docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,55 @@ For more details please see: [clusterctl alpha topology plan].
137137

138138
</aside>
139139

140+
## ClusterClass with MachinePools
141+
142+
ClusterClass also supports MachinePool workers. They work very similar to MachineDeployments. MachinePools
143+
can be specified in the ClusterClass template under the workers section like so:
144+
145+
```yaml
146+
apiVersion: cluster.x-k8s.io/v1beta1
147+
kind: ClusterClass
148+
metadata:
149+
name: docker-clusterclass-v0.1.0
150+
spec:
151+
workers:
152+
machinePools:
153+
- class: default-worker
154+
template:
155+
bootstrap:
156+
ref:
157+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
158+
kind: KubeadmConfigTemplate
159+
name: quick-start-default-worker-bootstraptemplate
160+
infrastructure:
161+
ref:
162+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
163+
kind: DockerMachinePoolTemplate
164+
name: quick-start-default-worker-machinepooltemplate
165+
```
166+
167+
They can then be similarly defined as workers in the cluster template like so:
168+
169+
```yaml
170+
apiVersion: cluster.x-k8s.io/v1beta1
171+
kind: Cluster
172+
metadata:
173+
name: my-docker-cluster
174+
spec:
175+
topology:
176+
workers:
177+
machinePools:
178+
- class: default-worker
179+
name: mp-0
180+
replicas: 4
181+
metadata:
182+
labels:
183+
mpLabel: mpLabelValue
184+
annotations:
185+
mpAnnotation: mpAnnotationValue
186+
failureDomain: region
187+
```
188+
140189
## ClusterClass with MachineHealthChecks
141190

142191
`MachineHealthChecks` can be configured in the ClusterClass for the control plane and for a
@@ -393,11 +442,11 @@ spec:
393442

394443
This section will explain more advanced features of ClusterClass patches.
395444

396-
### MachineDeployment variable overrides
445+
### MachineDeployment & MachinePool variable overrides
397446

398447
If you want to use many variations of MachineDeployments in Clusters, you can either define
399448
a MachineDeployment class for every variation or you can define patches and variables to
400-
make a single MachineDeployment class more flexible.
449+
make a single MachineDeployment class more flexible. The same applies for MachinePools.
401450

402451
In the following example we make the `instanceType` of a `AWSMachineTemplate` customizable.
403452
First we define the `workerMachineType` variable and the corresponding patch:
@@ -446,7 +495,7 @@ spec:
446495
```
447496

448497
In the Cluster resource the `workerMachineType` variable can then be set cluster-wide and
449-
it can also be overridden for an individual MachineDeployment.
498+
it can also be overridden for an individual MachineDeployment or MachinePool.
450499

451500
```yaml
452501
apiVersion: cluster.x-k8s.io/v1beta1
@@ -498,6 +547,12 @@ referenced in patches:
498547
- `builtin.machineDeployment.{infrastructureRef.name,bootstrap.configRef.name}`
499548
- Please note, these variables are only available when patching the templates of a MachineDeployment
500549
and contain the values of the current `MachineDeployment` topology.
550+
- `builtin.machinePool.{replicas,version,class,name,topologyName}`
551+
- Please note, these variables are only available when patching the templates of a MachinePool
552+
and contain the values of the current `MachinePool` topology.
553+
- `builtin.machinePool.{infrastructureRef.name,bootstrap.configRef.name}`
554+
- Please note, these variables are only available when patching the templates of a MachinePool
555+
and contain the values of the current `MachinePool` topology.
501556

502557
Builtin variables can be referenced just like regular variables, e.g.:
503558
```yaml
@@ -522,8 +577,8 @@ spec:
522577
**Tips & Tricks**
523578

524579
Builtin variables can be used to dynamically calculate image names. The version used in the patch
525-
will always be the same as the one we set in the corresponding MachineDeployment (works the same way
526-
with `.builtin.controlPlane.version`).
580+
will always be the same as the one we set in the corresponding MachineDeployment or MachinePool
581+
(works the same way with `.builtin.controlPlane.version`).
527582

528583
```yaml
529584
apiVersion: cluster.x-k8s.io/v1beta1
@@ -813,13 +868,17 @@ accessible via built in variables:
813868
- `builtin.machineDeployment.version`, represent the desired version for each specific MachineDeployment object;
814869
this version changes only after the upgrade for the control plane is completed, and in case of many
815870
MachineDeployments in the same cluster, they are upgraded sequentially.
871+
- `builtin.machinePool.version`, represent the desired version for each specific MachinePool object;
872+
this version changes only after the upgrade for the control plane is completed, and in case of many
873+
MachinePools in the same cluster, they are upgraded sequentially.
816874

817875
This info should provide the bases for developing version-aware patches, allowing the patch author to determine when a
818876
patch should adapt to the new Kubernetes version by choosing one of the above variables. In practice the
819877
following rules applies to the most common use cases:
820878

821879
- When developing a version-aware patch for the control plane, `builtin.controlPlane.version` must be used.
822880
- When developing a version-aware patch for MachineDeployments, `builtin.machineDeployment.version` must be used.
881+
- When developing a version-aware patch for MachinePools, `builtin.machinePool.version` must be used.
823882

824883
**Tips & Tricks**:
825884

docs/proposals/20210526-cluster-class-and-managed-topologies.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ status: provisional
7070
## Glossary
7171

7272
### ClusterClass
73-
A collection of templates that define a topology (control plane and machine deployments) to be used to continuously reconcile one or more Clusters.
73+
A collection of templates that define a topology (control plane, machine deployments and machine pools) to be used to continuously reconcile one or more Clusters.
7474

7575
### Topology
7676
A topology refers to a Cluster that provides a single control point to manage its own topology; the topology is defined by a ClusterClass.
@@ -85,7 +85,7 @@ We're enhancing the Cluster CRD and controller to use a ClusterClass resource to
8585

8686
Currently, Cluster API does not expose a native way to provision multiple clusters of the same configuration. The ClusterClass object is supposed to act as a collection of template references which can be used to create managed topologies.
8787

88-
Today, the Cluster object is a logical grouping of components which describe an underlying cluster. The user experience to create a cluster requires the user to create a bunch of underlying resources such as KCP (control plane provider), MachineDeployments, and infrastructure or bootstrap templates for those resources which logically end up representing the cluster. Since the cluster configuration is spread around multiple components, upgrading the cluster version is hard as it requires changes to different fields in different resources to perform an upgrade. The ClusterClass object aims at reducing this complexity by delegating the responsibility of lifecycle managing these underlying resources to the Cluster controller.
88+
Today, the Cluster object is a logical grouping of components which describe an underlying cluster. The user experience to create a cluster requires the user to create a bunch of underlying resources such as KCP (control plane provider), MachineDeployments, MachinePools and infrastructure or bootstrap templates for those resources which logically end up representing the cluster. Since the cluster configuration is spread around multiple components, upgrading the cluster version is hard as it requires changes to different fields in different resources to perform an upgrade. The ClusterClass object aims at reducing this complexity by delegating the responsibility of lifecycle managing these underlying resources to the Cluster controller.
8989

9090
This method of provisioning the cluster would act as a single control point for the entire cluster. Scaling the nodes, adding/removing sets of worker nodes and upgrading cluster kubernetes versions would be achievable by editing the topology. This would facilitate the maintenance of existing clusters as well as ease the creation of newer clusters.
9191

@@ -124,7 +124,7 @@ As a cluster operator, I want to use one `ClusterClass` to create multiple topol
124124

125125
#### Story 2 - Easier UX for Kubernetes version upgrades
126126
For a cluster operator, the UX to update the Kubernetes version of the control plane and worker nodes in the cluster should be easy.
127-
- Instead of individually modifying the KCP and each MachineDeployment, updating a single option should result in k8s version updates for all the CP and worker nodes.
127+
- Instead of individually modifying the KCP and each MachineDeployment or MachinePool, updating a single option should result in k8s version updates for all the CP and worker nodes.
128128

129129
**Note**: In order to complete the user story for all the providers, some of the advanced features (such as Extensibility/Transformation) are required. However, getting this in place even only for a subset of providers allows us to build and test a big chunk of the entire machinery.
130130

@@ -202,6 +202,10 @@ at high level the new CRD contains:
202202
- The reference to the infrastructureMachine template (e.g. AWSMachineTemplate) to be used when creating machine deployment machines.
203203
- Additional attributes to be set when creating the machine deployment object, like metadata, nodeDrainTimeout, rolloutStrategy etc.
204204
- The definition of a MachineHealthCheck to be created for monitoring machine deployment machines.
205+
- And/or a set of MachinePoolClasses, each one with:
206+
- The reference to the bootstrap template (e.g. KubeadmConfigTemplate) to be used when creating machine pools.
207+
- The reference to the infrastructureMachinePool template (e.g. DockerMachinePoolTemplate) to be used when creating machine pools.
208+
- Additional attributes to be set when creating the machine pool object, like metadata, nodeDrainTimeout, etc.
205209
- A list of patches, allowing to change above templates for each specific Cluster.
206210
- A list of variable definitions, defining a set of additional values the users can provide on each specific cluster;
207211
those values can be used in patches.
@@ -251,8 +255,9 @@ At high level the cluster topology is defined by:
251255
- The link to the MachineDeployment class defining the templates to use for this MachineDeployment
252256
- The number of replicas for this MachineDeployment as well as overrides/additional values for metadata, nodeDrainTimeout etc.
253257
Additionally it is also possible to override the control plane's MachineHealthCheck.
258+
- The above also applies for machine pools.
254259
- A set of variables allowing to customize the cluster topology through patches. Please note that it is also possible
255-
to define variable overrides for each MachineDeployments.
260+
to define variable overrides for each MachineDeployment or MachinePool.
256261

257262
More info in [writing a ClusterClass](https://cluster-api.sigs.k8s.io/tasks/experimental-features/cluster-class/write-clusterclass.html).
258263

@@ -264,14 +269,14 @@ API definitions; additionally please consider the following:
264269
**ClusterClass**
265270

266271
- It is not allowed to change apiGroup or Kind for the referenced templates (with the only exception of the bootstrap templates).
267-
- MachineDeploymentClass cannot be removed as long as they are used in Clusters.
272+
- MachineDeploymentClass and MachinePoolClass cannot be removed as long as they are used in Clusters.
268273
- It’s the responsibility of the ClusterClass author to ensure the patches are semantically valid, in the sense they
269274
generate valid templates for all the combinations of the corresponding variables in input.
270275
- Variables cannot be removed as long as they are used in Clusters.
271276
- When changing variable definitions, the system validates schema changes against existing clusters and blocks in case the changes are
272277
not compatible (the variable value is not compatible with the new variable definition).
273278

274-
Note: we are considering adding a field to allow smoother deprecations of MachineDeploymentClass and/or variables, but this
279+
Note: we are considering adding a field to allow smoother deprecations of MachineDeploymentClass, MachinePoolClass and/or variables, but this
275280
is not yet implemented as of today.
276281

277282
**Cluster**
@@ -420,10 +425,10 @@ This section talks about updating a Cluster which was created using a `ClusterCl
420425
1. User updates the `cluster.spec.topology`.
421426
2. System compares and updates InfrastructureCluster object, if the computed object after the change is different than the current one.
422427
3. System compares and updates ControlPlane object, if necessary. This includes also comparing and rotating the InfrastructureMachineTemplate, if necessary.
423-
4. System compares and updates MachineDeployment object, if necessary. This includes also
424-
1. Adding/Removing MachineDeployment, if necessary.
425-
2. Comparing and rotating the InfrastructureMachineTemplate and BootstrapTemplate for the existing MachineDeployments, if necessary.
426-
3. Comparing and updating the replicas, labels, annotations and version of the existing MachineDeployments, if necessary.
428+
4. System compares and updates MachineDeployment and/or MachinePool object, if necessary. This includes also
429+
1. Adding/Removing MachineDeployment/MachinePool, if necessary.
430+
2. Comparing and rotating the InfrastructureMachineTemplate and BootstrapTemplate for the existing MachineDeployments/MachinePools, if necessary.
431+
3. Comparing and updating the replicas, labels, annotations and version of the existing MachineDeployments/MachinePools, if necessary.
427432
5. System compares and updates MachineHealthCheck objects corresponding to ControlPlane or MachineDeployments, if necessary.
428433

429434
![Update cluster with ClusterClass](./images/cluster-class/update.png)

0 commit comments

Comments
 (0)