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