Skip to content

Commit 84706c7

Browse files
docs: move clusterctl to book
1 parent 7d6959b commit 84706c7

File tree

1 file changed

+94
-1
lines changed

1 file changed

+94
-1
lines changed
Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,94 @@
1-
# Clusterctl
1+
# Using `clusterctl` to create a cluster from scratch
2+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
3+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
4+
5+
6+
- [What is `clusterctl`?](#what-is-clusterctl)
7+
- [Creating a cluster](#creating-a-cluster)
8+
- [Creating a workload cluster using the management cluster](#creating-a-workload-cluster-using-the-management-cluster)
9+
10+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
11+
12+
This document provides an overview of how `clusterctl` works and explains how one can use `clusterctl`
13+
to create a Kubernetes cluster from scratch.
14+
15+
## What is `clusterctl`?
16+
17+
`clusterctl` is a CLI tool to create a Kubernetes cluster. `clusterctl` is provided by the [provider implementations](https://cluster-api.sigs.k8s.io/reference/providers).
18+
It uses Cluster API provider implementations to provision resources needed by the Kubernetes cluster.
19+
20+
## Creating a cluster
21+
22+
`clusterctl` needs 4 YAML files to start with: `provider-components.yaml`, `cluster.yaml`, `machines.yaml` ,
23+
`addons.yaml`.
24+
25+
* `provider-components.yaml` contains the *Custom Resource Definitions ([CRDs](https://Kubernetes.io/docs/concepts/extend-Kubernetes/api-extension/custom-resources/))*
26+
of all the resources that are managed by Cluster API. Some examples of these resources
27+
are: `Cluster`, `Machine`, `MachineSet`, etc. For more details about Cluster API resources
28+
click [here](https://cluster-api.sigs.k8s.io/architecture/controllers).
29+
* `cluster.yaml` defines an object of the resource type `Cluster`.
30+
* `machines.yaml` defines an object of the resource type `Machine`. Generally creates the machine
31+
that becomes the control-plane.
32+
* `addons.yaml` contains the addons for the provider.
33+
34+
Many providers implementations come with helpful scripts to generate these YAMLS. Provider implementation
35+
can be found [here](https://cluster-api.sigs.k8s.io/reference/providers).
36+
37+
`clusterctl` also comes with additional features. For example, `clusterctl` can also take in an optional
38+
`bootstrap-only-components.yaml` to provide resources to the bootstrap cluster without also providing them
39+
to the target cluster post-pivot.
40+
41+
For more details about all the supported options run:
42+
43+
```
44+
clusterctl create cluster --help
45+
```
46+
47+
After generating the YAML files run the following command:
48+
49+
```
50+
clusterctl create cluster --provider <PROVIDER> --bootstrap-type <BOOTSTRAP CLUSTER TYPE> -c cluster.yaml -m machines.yaml -p provider-components.yaml --addon-components addons.yaml
51+
```
52+
53+
Example usage:
54+
55+
```
56+
# VMware vSphere
57+
clusterctl create cluster --provider vsphere --bootstrap-type kind -c cluster.yaml -m machines.yaml -p provider-components.yaml --addon-components addons.yaml
58+
59+
# Amazon AWS
60+
clusterctl create cluster --provider aws --bootstrap-type kind -c cluster.yaml -m machines.yaml -p provider-components.yaml --addon-components addons.yaml
61+
```
62+
63+
**What happens when we run the command?**
64+
After running the command first it creates a local cluster. If `kind` was passed as the `--bootstrap-type`
65+
it creates a local [kind](https://kind.sigs.k8s.io/) cluster. This cluster is generally referred to as the *bootstrap cluster*.
66+
On this kind Kubernetes cluster the `provider-components.yaml` file is applied. This step loads the CRDs into
67+
the cluster. It also creates 2 [StatefulSet](https://Kubernetes.io/docs/concepts/workloads/controllers/statefulset/)
68+
pods that run the cluster api controller and the provider specific controller. These pods register the custom
69+
controllers that manage the newly defined resources (`Cluster`, `Machine`, `MachineSet`, etc).
70+
71+
Next, `clusterctl` applies the `cluster.yaml` and `machines.yaml` to the local kind Kubernetes cluster. This
72+
step creates a Kubernetes cluster with only a control-plane(as defined in `machines.yaml`) on the specified
73+
provider. This newly created cluster is generally referred to as the *management cluster* or *pivot cluster*
74+
or *initial target cluster*. The management cluster is responsible for creating and maintaining the work-load cluster.
75+
76+
Lastly, `clusterctl` moves all the CRDs and the custom controllers from the bootstrap cluster to the
77+
management cluster and deletes the locally created bootstrap cluster. This step is referred to as the *pivot*.
78+
79+
### Creating a workload cluster using the management cluster
80+
81+
The *workload cluster* also sometimes referred to as the *target cluster* is the Kubernetes cluster on to which
82+
the final application is deployed. The target cluster is responsible for handling the workload of the application,
83+
not the management cluster.
84+
85+
As the management cluster is up we can create a workload cluster by simply applying the appropriate
86+
`cluster.yaml`, `machines.yaml` and `machineset.yaml` on the management cluster. This will create the VMs(Nodes)
87+
as defined in these YAMLs. Following this, a bootstrap mechanism is used to create a Kubernetes cluster on these VMs.
88+
While any of the several bootstrapping mechanisms can be used `kubeadm` is the popular option.
89+
90+
**NOTE:** Workload clusters do not have any addons applied. Nodes in your workload clusters will be in the `NotReady`
91+
state until you apply addons for CNI plugin.
92+
93+
Once the target cluster is up the user can create the `Deployments`, `Services`, etc that handle the workload
94+
of the application.

0 commit comments

Comments
 (0)