sigs.k8s.io/cluster-api@v1.7.1/docs/book/src/clusterctl/commands/generate-cluster.md (about) 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 ```bash 8 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 --control-plane-machine-count=3 --worker-machine-count=3 > my-cluster.yaml 9 ``` 10 11 Generates 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 ```bash 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 ```bash 32 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 33 --infrastructure aws > my-cluster.yaml 34 ``` 35 36 or 37 38 ```bash 39 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 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 ```bash 49 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 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 ```bash 65 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 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, raw template URL, local file system folder or standard input 73 74 Use the `--from` flag to read cluster templates stored in a GitHub repository, raw template URL, in a local file system folder, 75 or from the standard input; e.g. 76 77 ```bash 78 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 79 --from https://github.com/my-org/my-repository/blob/main/my-template.yaml > my-cluster.yaml 80 ``` 81 82 or 83 84 ```bash 85 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 86 --from https://foo.bar/my-template.yaml > my-cluster.yaml 87 ``` 88 89 or 90 91 ```bash 92 clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 93 --from ~/my-template.yaml > my-cluster.yaml 94 ``` 95 96 or 97 98 ```bash 99 cat ~/my-template.yaml | clusterctl generate cluster my-cluster --kubernetes-version v1.28.0 \ 100 --from - > my-cluster.yaml 101 ``` 102 103 ### Variables 104 105 If the selected cluster template expects some environment variables, the user should ensure those variables are set in advance. 106 107 E.g. if the `AWS_CREDENTIALS` variable is expected for a cluster template targeting the `aws` infrastructure, you 108 should ensure the corresponding environment variable to be set before executing `clusterctl generate cluster`. 109 110 Please refer to the providers documentation for more info about the required variables or use the 111 `clusterctl generate cluster --list-variables` flag to get a list of variables names required by a cluster template. 112 113 The [clusterctl configuration](./../configuration.md) file can be used as alternative to environment variables.