|
| 1 | +# clusterctl generate cluster |
| 2 | + |
| 3 | +The `clusterctl generate cluster` command returns a YAML template for creating a workload cluster. |
| 4 | + |
| 5 | +For example |
| 6 | + |
| 7 | +``` |
| 8 | +clusterctl generate cluster my-cluster --kubernetes-version v1.16.3 --control-plane-machine-count=3 --worker-machine-count=3 > my-cluster.yaml |
| 9 | +``` |
| 10 | + |
| 11 | +Geenerates a YAML file named `my-cluster.yaml` with a predefined list of Cluster API objects; Cluster, Machines, |
| 12 | +Machine Deployments, etc. to be deployed in the current namespace (in case, use the `--target-namespace` flag to |
| 13 | +specify a different target namespace). |
| 14 | + |
| 15 | +Then, the file can be modified using your editor of choice; when ready, run the following command |
| 16 | +to apply the cluster manifest. |
| 17 | + |
| 18 | +``` |
| 19 | +kubectl apply -f my-cluster.yaml |
| 20 | +``` |
| 21 | + |
| 22 | +### Selecting the infrastructure provider to use |
| 23 | + |
| 24 | +The `clusterctl generate cluster` command uses smart defaults in order to simplify the user experience; in the example above, |
| 25 | +it detects that there is only an `aws` infrastructure provider in the current management cluster and so it automatically |
| 26 | +selects a cluster template from the `aws` provider's repository. |
| 27 | + |
| 28 | +In case there is more than one infrastructure provider, the following syntax can be used to select which infrastructure |
| 29 | +provider to use for the workload cluster: |
| 30 | + |
| 31 | +``` |
| 32 | +clusterctl generate cluster my-cluster --kubernetes-version v1.16.3 \ |
| 33 | + --infrastructure aws > my-cluster.yaml |
| 34 | +``` |
| 35 | + |
| 36 | +or |
| 37 | + |
| 38 | +``` |
| 39 | +clusterctl generate cluster my-cluster --kubernetes-version v1.16.3 \ |
| 40 | + --infrastructure aws:v0.4.1 > my-cluster.yaml |
| 41 | +``` |
| 42 | + |
| 43 | +### Flavors |
| 44 | + |
| 45 | +The infrastructure provider authors can provide different types of cluster templates, or flavors; use the `--flavor` flag |
| 46 | +to specify which flavor to use; e.g. |
| 47 | + |
| 48 | +``` |
| 49 | +clusterctl generate cluster my-cluster --kubernetes-version v1.16.3 \ |
| 50 | + --flavor high-availability > my-cluster.yaml |
| 51 | +``` |
| 52 | + |
| 53 | +Please refer to the providers documentation for more info about available flavors. |
| 54 | + |
| 55 | +### Alternative source for cluster templates |
| 56 | + |
| 57 | +clusterctl uses the provider's repository as a primary source for cluster templates; the following alternative sources |
| 58 | +for cluster templates can be used as well: |
| 59 | + |
| 60 | +#### ConfigMaps |
| 61 | + |
| 62 | +Use the `--from-config-map` flag to read cluster templates stored in a Kubernetes ConfigMap; e.g. |
| 63 | + |
| 64 | +``` |
| 65 | +clusterctl generate cluster my-cluster --kubernetes-version v1.16.3 \ |
| 66 | + --from-config-map my-templates > my-cluster.yaml |
| 67 | +``` |
| 68 | + |
| 69 | +Also following flags are available `--from-config-map-namespace` (defaults to current namespace) and `--from-config-map-key` |
| 70 | +(defaults to `template`). |
| 71 | + |
| 72 | +#### GitHub or local file system folder |
| 73 | + |
| 74 | +Use the `--from` flag to read cluster templates stored in a GitHub repository or in a local file system folder; e.g. |
| 75 | + |
| 76 | +``` |
| 77 | +clusterctl generate cluster my-cluster --kubernetes-version v1.16.3 \ |
| 78 | + --from https://github.com/my-org/my-repository/blob/master/my-template.yaml > my-cluster.yaml |
| 79 | +``` |
| 80 | + |
| 81 | +or |
| 82 | + |
| 83 | +``` |
| 84 | +clusterctl generate cluster my-cluster --kubernetes-version v1.16.3 \ |
| 85 | + --from ~/my-template.yaml > my-cluster.yaml |
| 86 | +``` |
| 87 | + |
| 88 | +### Variables |
| 89 | + |
| 90 | +If the selected cluster template expects some environment variables, the user should ensure those variables are set in advance. |
| 91 | + |
| 92 | +E.g. if the `AWS_CREDENTIALS` variable is expected for a cluster template targeting the `aws` infrastructure, you |
| 93 | +should ensure the corresponding environment variable to be set before executing `clusterctl generate cluster`. |
| 94 | + |
| 95 | +Please refer to the providers documentation for more info about the required variables or use the |
| 96 | +`clusterctl generate cluster --list-variables` flag to get a list of variables names required by a cluster template. |
| 97 | + |
| 98 | +The [clusterctl configuration](./../configuration.md) file can be used as alternative to environment variables. |
0 commit comments