// Module included in the following assemblies:
//
// * rosa_cluster_admin/rosa_nodes/rosa-managing-worker-nodes.adoc

:_mod-docs-content-type: PROCEDURE
[id="creating_machine_pools_cli_capres_{context}"]
= Creating a machine pool with Capacity Reservations using the {rosa-cli}

[role="_abstract"]
You can create a new machine pool with Capacity Reservations by using the {rosa-cli-first}. Both On-Demand Capacity Reservations and Capacity Blocks for ML are supported.

[NOTE]
====
Currently, autoscaling is not supported on machine pools with Capacity Reservations.
====

.Prerequisites

* You installed and configured the latest {rosa-cli}.
* You logged in to your Red{nbsp}Hat account using the {rosa-cli}.
* You created a {product-title} cluster version 4.19 or above.
* The cluster already has a machine pool that is not using a Capacity Reservation or taints. The machine pool must have at least 2 worker nodes.
* You have a Capacity Reservation ID and capacity is reserved for the instance type required in the Availability Zone (AZ) of the machine pool that you are creating.

.Procedure

* Create the machine pool and define the Capacity Reservation preference and ID by running the following command:
+
[source,terminal]
----
$ rosa create machinepool --cluster=<cluster_name> \
                          --name=<machine_pool_id> \
                          --replicas=<replica_count> \
                          --capacity-reservation-preference none | open | capacity-reservations-only \
                          --capacity-reservation-id cr-<capacity_reservation_id> \
                          --instance-type=<instance_type> \
                          --subnet <subnet_id>
----

where:

*<machine_pool_id>*:: Specifies the name of the machine pool.
*<replica_count>*:: Specifies the number of provisioned compute nodes. If you deploy {product-title} using a single AZ, this defines the number of compute nodes provisioned to the machine pool for the AZ. If you deploy your cluster using multiple AZs, this defines the total number of compute nodes provisioned across all AZs. For multi-zone clusters, the compute node count must be a multiple of 3. The `--replicas` argument is required when autoscaling is not configured.
*<capacity_reservation_preference>*:: Specifies the Capacity Reservation behaviour. Valid preferences include:

* `none`: The instance does not use a Capacity Reservation even if one is available. The instance runs as an EC2 On-Demand instance. Choose this option when you want to avoid consuming purchased reserved capacity and use it for other workloads.
* `open`: The instance can run in any `open` Capacity Reservation that has matching attributes such as the instance type, platform, AZ, or tenancy. Choose this option for flexibility; if a reservation is not available, the instance can use regular unreserved EC2 capacity.
* `capacity-reservations-only`: The instance can only run in a Capacity Reservation. If capacity is not available, the instance fails to launch.

*cr-<capacity_reservation_id>*:: Specifies the reservation ID. You get an ID in the `cr-<capacity_reservation_id>` format when you purchase a Capacity Reservation from AWS. The ID can be for both On-Demand Capacity Reservations or Capacity Blocks for ML, you do not need to specify the reservation type.
*<instance_type>*:: *Optional*: Specifies the instance type for the compute nodes in your machine pool. The instance type defines the vCPU and memory allocation for each compute node in the pool. Replace `<instance_type>` with an instance type. The default is `m5.xlarge`. You cannot change the instance type for a machine pool after the pool is created.
*<subnet_id>*:: *Optional*: Specifies the subnet ID. For Bring Your Own Virtual Private Cloud (BYO VPC) clusters, you can select a subnet to create a single-AZ machine pool. If you select a subnet that was not specified during the initial cluster creation, you must tag the subnet with the `kubernetes.io/cluster/<infra_id>` key and `shared` value. Customers can obtain the Infra ID by running the following command:
+
[source,terminal]
----
$ rosa describe cluster --cluster <cluster_name>|grep "Infra ID:"
----
+
.Example output
[source,terminal]
----
Infra ID:                   mycluster-xqvj7
----

.Example

The following example creates a machine pool called `mymachinepool` that uses the `c5.xlarge` instance type and has 1 compute node replica. The example also adds a Capacity Reservation ID. Example input and output:

[source,terminal]
----
$ rosa create machinepool --cluster=mycluster --name=mymachinepool --replicas 1 --capacity-reservation-id <capacity_reservation_id> --subnet <subnet_id> --instance-type c5.xlarge
----


[source,terminal]
----
I: Checking available instance types for machine pool 'mymachinepool'
I: Machine pool 'mymachinepool' created successfully on hosted cluster 'mycluster'
----

.Verification

You can list all machine pools on your cluster or describe individual machine pools.

* List the available machine pools on your cluster by running the following command:
+
[source,terminal]
----
$ rosa list machinepools --cluster <cluster_name>
----

* Describe the information of a specific machine pool in your cluster by running the following command.
+
[source,terminal]
----
$ rosa describe machinepool --cluster <cluster_name> --machinepool <machine_pool_name>
----
+
.Example output
[source,terminal]
----
ID:                         <machine_pool_name>
Cluster ID:                 <cluster_id>
Autoscaling:                No
Desired replicas:           1
Current replicas:           1
Instance type:              c5.xlarge
Labels:
Tags:                       red-hat-managed=true, api.openshift.com/environment=production, api.openshift.com/id=<cluster_name>, api.openshift.com/legal-entity-id=<legal_entity_id>, api.openshift.com/name=<cluster_name>, api.openshift.com/nodepool-hypershift=<cluster_name>-<machine_pool_name>, api.openshift.com/nodepool-ocm=<machine_pool_name>, red-hat-clustertype=rosa
Taints:
Availability zone:          us-east-1a
Subnet:                     <subnet_id>
Disk Size:                  300 GiB
Version:                    4.19.10
EC2 Metadata Http Tokens:   optional
Autorepair:                 Yes
Tuning configs:
Kubelet configs:
Additional security group IDs:
Node drain grace period:
Capacity Reservation:
    - ID:                   <capacity_reservation_id>
    - Type:                 OnDemand
    - Preference:           open
Management upgrade:
    - Type:                 Replace
    - Max surge:            1
    - Max unavailable:      0
Message:                    Minimum availability requires 1 replicas, current 1 available
----
+
The output should include the Capacity Reservation ID, type, and preference.
