Skip to content

Commit e5e1b62

Browse files
authored
Merge pull request #6026 from killianmuldoon/docs/operating-a-clusterclass
📖 Extend Operating a Managed Cluster doc
2 parents a52bb72 + a15113d commit e5e1b62

File tree

1 file changed

+182
-4
lines changed

1 file changed

+182
-4
lines changed

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

Lines changed: 182 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# Operating a managed Cluster
22

3-
## Upgrade the Cluster
3+
The `spec.topology` field added to the Cluster object as part of ClusterClass allows changes made on the Cluster to be propagated across all relevant objects. This means the Cluster object can be used as a single point of control for making changes to objects that are part of the Cluster, including the ControlPlane and MachineDeployments.
44

5-
The `spec.topology` field added to the Cluster object as part of ClusterClass allows changes made on the Cluster to be propagated across all relevant objects. This turns a Kubernetes cluster upgrade into a one-touch operation.
6-
Let's assume we have created a CAPD cluster with ClusterClass and Kubernetes v1.21.2 (as documented in the [Quick Start guide]). Looking at the cluster, the version of the control plane and the MachineDeployments is v1.21.2.
5+
A managed Cluster can be used to:
6+
* [Upgrade a Cluster](#upgrade-a-cluster)
7+
* [Scale a ControlPlane](#scale-a-controlplane)
8+
* [Scale a MachineDeployment](#scale-a-machinedeployment)
9+
* [Add a MachineDeployment](#add-a-machinedeployment)
10+
* [Use variables in a Cluster](#use-variables)
11+
* [Rebase a Cluster to a different ClusterClass](#rebase-a-cluster)
12+
13+
14+
## Upgrade a Cluster
15+
Using a managed topology the operation to upgrade a Kubernetes cluster is a one-touch operation.
16+
Let's assume we have created a CAPD cluster with ClusterClass and specified Kubernetes v1.21.2 (as documented in the [Quick Start guide]). Specifying the version is done when running `clusterctl generate cluster`. Looking at the cluster, the version of the control plane and the MachineDeployments is v1.21.2.
717

818
```bash
919
> kubectl get kubeadmcontrolplane,machinedeployments
@@ -17,12 +27,21 @@ machinedeployment.cluster.x-k8s.io/clusterclass-quickstart-linux-workers-XXXX
1727

1828
To update the Cluster the only change needed is to the `version` field under `spec.topology` in the Cluster object.
1929

20-
2130
Change `1.21.2` to `1.22.0` as below.
2231

2332
```bash
2433
kubectl patch cluster clusterclass-quickstart --type json --patch '[{"op": "replace", "path": "/spec/topology/version", "value": "v1.22.0"}]'
2534
```
35+
36+
The patch will make the following change to the Cluster yaml:
37+
```diff
38+
spec:
39+
topology:
40+
class: quick-start
41+
+ version: v1.22.0
42+
- version: v1.21.2
43+
```
44+
2645
**Important Note**: A +2 minor Kubernetes version upgrade is not allowed in Cluster Topologies. This is to align with existing control plane providers, like KubeadmControlPlane provider, that limit a +2 minor version upgrade. Example: Upgrading from `1.21.2` to `1.23.0` is not allowed.
2746

2847
The upgrade will take some time to roll out as it will take place machine by machine with older versions of the machines only being removed after healthy newer versions come online.
@@ -42,3 +61,162 @@ kubeadmcontrolplane.controlplane.cluster.x-k8s.io/clusterclass-quickstart-XXXX
4261
NAME CLUSTER REPLICAS READY UPDATED UNAVAILABLE PHASE AGE VERSION
4362
machinedeployment.cluster.x-k8s.io/clusterclass-quickstart-linux-workers-XXXX clusterclass-quickstart 1 1 1 0 Running 7m29s v1.22.0
4463
```
64+
65+
## Scale a MachineDeployment
66+
When using a managed topology scaling of MachineDeployments, both up and down, should be done through the Cluster topology.
67+
68+
Assume we have created a CAPD cluster with ClusterClass and Kubernetes v1.23.3 (as documented in the [Quick Start guide]). Initially we should have a MachineDeployment with 3 replicas. Running
69+
```bash
70+
kubectl get machinedeployments
71+
```
72+
Will give us:
73+
```bash
74+
NAME CLUSTER REPLICAS READY UPDATED UNAVAILABLE PHASE AGE VERSION
75+
machinedeployment.cluster.x-k8s.io/capi-quickstart-md-0-XXXX capi-quickstart 3 3 3 0 Running 21m v1.23.3
76+
```
77+
We can scale up or down this MachineDeployment through the Cluster object by changing the replicas field under `/spec/topology/workers/machineDeployments/0/replicas`
78+
The `0` in the path refers to the position of the target MachineDeployment in the list of our Cluster topology. As we only have one MachineDeployment we're targeting the first item in the list under `/spec/topology/workers/machineDeployments/`.
79+
80+
To change this value with a patch:
81+
```bash
82+
kubectl patch cluster capi-quickstart --type json --patch '[{"op": "replace", "path": "/spec/topology/workers/machineDeployments/0/replicas", "value": 1}]'
83+
```
84+
85+
This patch will make the following changes on the Cluster yaml:
86+
```diff
87+
spec:
88+
topology:
89+
workers:
90+
machineDeployments:
91+
- class: default-worker
92+
name: md-0
93+
metadata: {}
94+
+ replicas: 1
95+
- replicas: 3
96+
```
97+
After a minute the MachineDeployment will have scaled down to 1 replica:
98+
99+
```bash
100+
NAME CLUSTER REPLICAS READY UPDATED UNAVAILABLE PHASE AGE VERSION
101+
capi-quickstart-md-0-XXXXX capi-quickstart 1 1 1 0 Running 25m v1.23.3
102+
```
103+
104+
As well as scaling a MachineDeployment, Cluster operators can edit the labels and annotations applied to a running MachineDeployment using the Cluster topology as a single point of control.
105+
106+
## Add a MachineDeployment
107+
MachineDeployments in a managed Cluster are defined in the Cluster's topology. Cluster operators can add a MachineDeployment to a living Cluster by adding it to the `cluster.spec.topology.workers.machineDeployments` field.
108+
109+
Assume we have created a CAPD cluster with ClusterClass and Kubernetes v1.23.3 (as documented in the [Quick Start guide]). Initially we should have a single MachineDeployment with 3 replicas. Running
110+
```bash
111+
kubectl get machinedeployments
112+
```
113+
114+
Will give us:
115+
```bash
116+
NAME CLUSTER REPLICAS READY UPDATED UNAVAILABLE PHASE AGE VERSION
117+
machinedeployment.cluster.x-k8s.io/capi-quickstart-md-0-XXXX capi-quickstart 3 3 3 0 Running 21m v1.23.3
118+
```
119+
120+
121+
A new MachineDeployment can be added to the Cluster by adding a new MachineDeployment spec under `/spec/topology/workers/machineDeployments/`. To do so we can patch our Cluster with:
122+
```bash
123+
kubectl patch cluster capi-quickstart --type json --patch '[{"op": "add", "path": "/spec/topology/workers/machineDeployments/-", "value": {"name": "second-deployment", "replicas": 1, "class": "default-worker"} }]'
124+
```
125+
This patch will make the below changes on the Cluster yaml:
126+
```diff
127+
spec:
128+
topology:
129+
workers:
130+
machineDeployments:
131+
- class: default-worker
132+
metadata: {}
133+
replicas: 3
134+
name: md-0
135+
+ - class: default-worker
136+
+ metadata: {}
137+
+ replicas: 1
138+
+ name: second-deployment
139+
```
140+
141+
After a minute to scale the new MachineDeployment we get:
142+
```bash
143+
NAME CLUSTER REPLICAS READY UPDATED UNAVAILABLE PHASE AGE VERSION
144+
capi-quickstart-md-0-XXXX capi-quickstart 1 1 1 0 Running 39m v1.23.3
145+
capi-quickstart-second-deployment-XXXX capi-quickstart 1 1 1 0 Running 99s v1.23.3
146+
```
147+
Our second deployment uses the same underlying MachineDeployment class `default-worker` as our initial deployment. In this case they will both have exactly the same underlying machine templates. In order to modify the templates MachineDeployments are based on take a look at [Changing a ClusterClass].
148+
149+
A similar process as that described here - removing the MachineDeployment from `cluster.spec.topology.workers.machineDeployments` - can be used to delete a running MachineDeployment from an active Cluster.
150+
151+
## Scale a ControlPlane
152+
When using a managed topology scaling of ControlPlane Machines, where the Cluster is using a topology that includes ControlPlane MachineInfrastructure, should be done through the Cluster topology.
153+
154+
This is done by changing the ControlPlane replicas field at `/spec/topology/controlPlane/replica` in the Cluster object. The command is:
155+
156+
```bash
157+
kubectl patch cluster capi-quickstart --type json --patch '[{"op": "replace", "path": "/spec/topology/controlPlane/replicas", "value": 1}]'
158+
```
159+
160+
This patch will make the below changes on the Cluster yaml:
161+
```diff
162+
spec:
163+
topology:
164+
controlPlane:
165+
metadata: {}
166+
+ replicas: 1
167+
- replicas: 3
168+
```
169+
170+
As well as scaling a ControlPlane, Cluster operators can edit the labels and annotations applied to a running ControlPlane using the Cluster topology as a single point of control.
171+
172+
173+
## Use variables
174+
A ClusterClass can use variables and patches in order to allow flexible customization of Clusters derived from a ClusterClass. Variable definition allows two or more Cluster topologies derived from the same ClusterClass to have different specs, with the differences controlled by variables in the Cluster topology.
175+
176+
Assume we have created a CAPD cluster with ClusterClass and Kubernetes v1.23.3 (as documented in the [Quick Start guide]). Our Cluster has a variable `etcdImageTag` as defined in the ClusterClass. The variable is not set on our Cluster. Some variables, depending on their definition in a ClusterClass, may need to be specified by the Cluster operator for every Cluster created using a given ClusterClass.
177+
178+
In order to specify the value of a variable all we have to do is set the value in the Cluster topology.
179+
180+
We can see the current unset variable with:
181+
```bash
182+
kubectl get cluster capi-quickstart -o jsonpath='{.spec.topology.variables[1]}'
183+
184+
```
185+
Which will return something like:
186+
```bash
187+
{"name":"etcdImageTag","value":""}
188+
```
189+
190+
In order to run a different version of etcd in new ControlPlane machines - the part of the spec this variable sets - change the value using the below patch:
191+
```bash
192+
kubectl patch cluster capi-quickstart --type json --patch '[{"op": "replace", "path": "/spec/topology/variables/1/value", "value": "3.5.0"}]'
193+
```
194+
195+
Running the patch makes the following change to the Cluster yaml:
196+
```diff
197+
spec:
198+
topology:
199+
variables:
200+
- name: imageRepository
201+
value: k8s.gcr.io
202+
- name: etcdImageTag
203+
value: ""
204+
- name: coreDNSImageTag
205+
+ value: "3.5.0"
206+
- value: ""
207+
208+
```
209+
Retrieving the variable value from the Cluster object, with `kubectl get cluster capi-quickstart -o jsonpath='{.spec.topology.variables[1]}'` we can see:
210+
```bash
211+
{"name":"etcdImageTag","value":"3.5.0"}
212+
```
213+
Note: Changing the etcd version may have unintended impacts on a running Cluster. For safety the cluster should be reapplied after running the above variable patch.
214+
215+
## Rebase a Cluster
216+
To perform more significant changes using a Cluster as a single point of control, it may be necessary to change the ClusterClass that the Cluster is based on. This is done by changing the class referenced in `/spec/topology/class`.
217+
218+
To read more about changing an underlying class please refer to [ClusterClass rebase].
219+
220+
[Quick Start guide]: ../../../user/quick-start.md
221+
[ClusterClass rebase]: ./change-clusterclass.md#rebase
222+
[Changing a ClusterClass]: ./change-clusterclass.md

0 commit comments

Comments
 (0)