// Module included in the following assemblies:
//
// * installing/installing_aws/ipi/installing-aws-outposts.adoc

:_mod-docs-content-type: PROCEDURE
[id="aws-outposts-machine-set_{context}"]
= Creating a compute machine set that deploys edge compute machines on an Outpost

To create edge compute machines on AWS Outposts, you must create a new compute machine set with a compatible configuration.

.Prerequisites

* You have an AWS Outposts site.

* You have installed an {product-title} cluster into a custom VPC on AWS.

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

* You have installed the {oc-first}.

.Procedure

. List the compute machine sets in your cluster by running the following command:
+
[source,terminal]
----
$ oc get machinesets.machine.openshift.io -n openshift-machine-api
----
+
.Example output
[source,text]
----
NAME                            DESIRED   CURRENT   READY   AVAILABLE   AGE
<original_machine_set_name_1>   1         1         1       1           55m
<original_machine_set_name_2>   1         1         1       1           55m
----

. Record the names of the existing compute machine sets.

. Create a YAML file that contains the values for a new compute machine set custom resource (CR) by using one of the following methods:

** Copy an existing compute machine set configuration into a new file by running the following command:
+
[source,terminal]
----
$ oc get machinesets.machine.openshift.io <original_machine_set_name_1> \
  -n openshift-machine-api -o yaml > <new_machine_set_name_1>.yaml
----
+
You can edit this YAML file with your preferred text editor.

** Create an empty YAML file named `<new_machine_set_name_1>.yaml` with your preferred text editor and include the required values for your new compute machine set.
+
If you are not sure which value to set for a specific field, you can view values of an existing compute machine set CR by running the following command:
+
[source,terminal]
----
$ oc get machinesets.machine.openshift.io <original_machine_set_name_1> \
  -n openshift-machine-api -o yaml
----
+
--
.Example output
[source,yaml]
----
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  labels:
    machine.openshift.io/cluster-api-cluster: <infrastructure_id> # <1>
  name: <infrastructure_id>-<role>-<availability_zone> # <2>
  namespace: openshift-machine-api
spec:
  replicas: 1
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-cluster: <infrastructure_id>
      machine.openshift.io/cluster-api-machineset: <infrastructure_id>-<role>-<availability_zone>
  template:
    metadata:
      labels:
        machine.openshift.io/cluster-api-cluster: <infrastructure_id>
        machine.openshift.io/cluster-api-machine-role: <role>
        machine.openshift.io/cluster-api-machine-type: <role>
        machine.openshift.io/cluster-api-machineset: <infrastructure_id>-<role>-<availability_zone>
    spec:
      providerSpec: # <3>
# ...
----
<1> The cluster infrastructure ID.
<2> A default node label. For AWS Outposts, you use the `outposts` role.
<3> The omitted `providerSpec` section includes values that must be configured for your Outpost.
--

. Configure the new compute machine set to create edge compute machines in the Outpost by editing the `<new_machine_set_name_1>.yaml` file:
+
--
.Example compute machine set for AWS Outposts
[source,yaml]
----
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  labels:
    machine.openshift.io/cluster-api-cluster: <infrastructure_id> # <1>
  name: <infrastructure_id>-outposts-<availability_zone> # <2>
  namespace: openshift-machine-api
spec:
  replicas: 1
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-cluster: <infrastructure_id>
      machine.openshift.io/cluster-api-machineset: <infrastructure_id>-outposts-<availability_zone>
  template:
    metadata:
      labels:
        machine.openshift.io/cluster-api-cluster: <infrastructure_id>
        machine.openshift.io/cluster-api-machine-role: outposts
        machine.openshift.io/cluster-api-machine-type: outposts
        machine.openshift.io/cluster-api-machineset: <infrastructure_id>-outposts-<availability_zone>
    spec:
      metadata:
        labels:
          node-role.kubernetes.io/outposts: ""
          location: outposts
      providerSpec:
        value:
          ami:
            id: <ami_id> # <3>
          apiVersion: machine.openshift.io/v1beta1
          blockDevices:
            - ebs:
                volumeSize: 120
                volumeType: gp2 # <4>
          credentialsSecret:
            name: aws-cloud-credentials
          deviceIndex: 0
          iamInstanceProfile:
            id: <infrastructure_id>-worker-profile
          instanceType: m5.xlarge # <5>
          kind: AWSMachineProviderConfig
          placement:
            availabilityZone: <availability_zone>
            region: <region> # <6>
          securityGroups:
            - filters:
              - name: tag:Name
                values:
                  - <infrastructure_id>-worker-sg
          subnet:
            id: <subnet_id> # <7>
          tags:
            - name: kubernetes.io/cluster/<infrastructure_id>
              value: owned
          userDataSecret:
            name: worker-user-data
      taints: # <8>
        - key: node-role.kubernetes.io/outposts
          effect: NoSchedule
----
<1> Specifies the cluster infrastructure ID.
<2> Specifies the name of the compute machine set. The name is composed of the cluster infrastructure ID, the `outposts` role name, and the Outpost availability zone.
<3> Specifies the Amazon Machine Image (AMI) ID.
<4> Specifies the EBS volume type. AWS Outposts requires gp2 volumes.
<5> Specifies the AWS instance type. You must use an instance type that is configured in your Outpost.
<6> Specifies the AWS region in which the Outpost availability zone exists.
<7> Specifies the dedicated subnet for your Outpost.
<8> Specifies a taint to prevent workloads from being scheduled on nodes that have the `node-role.kubernetes.io/outposts` label. To schedule user workloads in the Outpost, you must specify a corresponding toleration in the `Deployment` resource for your application.
--

. Save your changes.

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

.Verification

* To verify that the compute machine set is created, list the compute machine sets in your cluster by running the following command:
+
[source,terminal]
----
$ oc get machinesets.machine.openshift.io -n openshift-machine-api
----
+
.Example output
[source,text]
----
NAME                            DESIRED   CURRENT   READY   AVAILABLE   AGE
<new_machine_set_name_1>        1         1         1       1           4m12s
<original_machine_set_name_1>   1         1         1       1           55m
<original_machine_set_name_2>   1         1         1       1           55m
----

* To list the machines that are managed by the new compute machine set, run the following command:
+
[source,terminal]
----
$ oc get -n openshift-machine-api machines.machine.openshift.io \
  -l machine.openshift.io/cluster-api-machineset=<new_machine_set_name_1>
----
+
.Example output
[source,text]
----
NAME                             PHASE          TYPE        REGION      ZONE         AGE
<machine_from_new_1>             Provisioned    m5.xlarge   us-east-1   us-east-1a   25s
<machine_from_new_2>             Provisioning   m5.xlarge   us-east-1   us-east-1a   25s
----

* To verify that a machine created by the new compute machine set has the correct configuration, examine the relevant fields in the CR for one of the new machines by running the following command:
+
[source,terminal]
----
$ oc describe machine <machine_from_new_1> -n openshift-machine-api
----
