// Module included in the following assemblies:
//
// * machine_management/cluster_api_machine_management/cluster-api-using.adoc

:_mod-docs-content-type: PROCEDURE
[id="capi-creating-machine-set_{context}"]
= Creating a Cluster API compute machine set

[role="_abstract"]
You can create compute machine sets that use the Cluster API to dynamically manage the machine compute resources for specific workloads of your choice.

.Prerequisites

* You have deployed an {product-title} cluster.

* You have enabled the use of the Cluster API.

* You have access to the cluster using an account with `cluster-admin` permissions.

* You have installed the {oc-first}.

* You have created the machine template resource.

.Procedure

. Create a YAML file similar to the following. This procedure uses `<machine_set_resource_file>.yaml` as an example file name.
+
--
[source,yaml]
----
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineSet
metadata:
  name: <machine_set_name>
  namespace: openshift-cluster-api
spec:
  clusterName: <cluster_name>
  replicas: 1
  selector:
    matchLabels:
      test: example
  template:
    metadata:
      labels:
        test: example
    spec:
# ...
----

where:

`metadata.name`:: Specifies a name for the compute machine set.
The cluster ID, machine role, and region form a typical pattern for this value in the following format: `<cluster_name>-<role>-<region>`.
`spec.clusterName`:: Specifies the name of the cluster.
Obtain the value of the cluster ID by running the following command:

[source,terminal]
----
$  oc get infrastructure cluster \
   -o jsonpath='{.status.infrastructureName}'
----

`spec.template.spec`:: Specifies the details for your environment. These parameters are provider specific. For more information, see the sample Cluster API compute machine set YAML for your provider.
--

. Create the compute machine set CR by running the following command:
+
[source,terminal]
----
$ oc create -f <machine_set_resource_file>.yaml
----

. Confirm that the compute machine set CR is created by running the following command:
+
[source,terminal]
----
$ oc get machineset.cluster.x-k8s.io -n openshift-cluster-api
----
+
.Example output
[source,text]
----
NAME                 CLUSTER          REPLICAS   READY   AVAILABLE   AGE   VERSION
<machine_set_name>   <cluster_name>   1          1       1           17m
----
+
When the new compute machine set is available, the `REPLICAS` and `AVAILABLE` values match. If the compute machine set is not available, wait a few minutes and run the command again.

.Verification

* To verify that the compute machine set is creating machines according to your required configuration, review the lists of machines and nodes in the cluster by running the following commands:
+
** View the list of Cluster API machines:
+
[source,terminal]
----
$ oc get machine.cluster.x-k8s.io -n openshift-cluster-api
----
+
.Example output
[source,text]
----
NAME                             CLUSTER          NODENAME                                 PROVIDERID      PHASE     AGE     VERSION
<machine_set_name>-<string_id>   <cluster_name>   <ip_address>.<region>.compute.internal   <provider_id>   Running   8m23s
----
+
** View the list of nodes:
+
[source,terminal]
----
$ oc get node
----
+
.Example output
[source,text]
----
NAME                                       STATUS   ROLES    AGE     VERSION
<ip_address_1>.<region>.compute.internal   Ready    worker   5h14m   v1.28.5
<ip_address_2>.<region>.compute.internal   Ready    master   5h19m   v1.28.5
<ip_address_3>.<region>.compute.internal   Ready    worker   7m      v1.28.5
----
