[Yandex Cloud documentation](../../../index.md) > [Yandex Managed Service for Kubernetes](../../index.md) > [Step-by-step guides](../index.md) > Managing a node group > Creating a group with nodes from a reserved instance pool

# Creating a group with nodes from a Yandex Compute Cloud reserved instance pool


{% note warning %}

Reserved instance pools are billable: you pay for the whole unused volume of reserved computing resources of VMs, GPU clusters, and software accelerated networks according to the [Yandex Compute Cloud pricing policy](../../../compute/pricing.md). For more information, see [Using reserved instance pools](../../../compute/pricing.md#pool).

{% endnote %}

_The reserved instance pool feature is at the [Preview stage](../../../overview/concepts/launch-stages.md)._

A _reserved instance pool_ is the total of computing resources reserved by the user in a given [availability zone](../../../overview/concepts/geo-scope.md) to secure their guaranteed availability to the user for the purpose of creating [VMs](../../../compute/concepts/vm.md) of a particular [configuration](../../../compute/concepts/performance-levels.md#available-configurations) in this availability zone.

In Managed Service for Kubernetes, you can use reserved instance pools for fixed-size [node groups](../../concepts/index.md#node-group). This ensures resource availability for cluster nodes.

For more information, see [Reserved instance pools for Yandex Managed Service for Kubernetes node groups](../../concepts/node-group/reserved-pools.md) and [Reserved instance pools in Compute Cloud](../../../compute/concepts/reserved-pools.md). 

{% note warning %}

Reserved instance pools _are not supported_ for node groups with the following properties:
* [Autoscaling](../../concepts/node-group/cluster-autoscaler.md)
* [vCPU performance levels below 100%](../../../compute/concepts/performance-levels.md)
* [Preemptible VMs](../../../compute/concepts/preemptible-vm.md)
* [VM placement groups](../../../compute/concepts/placement-groups.md)

{% endnote %}

## Creating a node group in a single availability zone with nodes from a reserved instance pool in that zone {#single-zone}

1. [Create](../../../compute/operations/reserved-pools/create-reserved-pool.md) a reserved instance pool with a configuration you want to use for Managed Service for Kubernetes cluster nodes.

    {% note info %}
    
    Make sure the following properties are identical in the node group and reserved instance pool configurations:
    * [Platform](../../../compute/concepts/vm-platforms.md)
    * Number of vCPUs
    * Amount of RAM
    * [Availability zone](../../../overview/concepts/geo-scope.md)
    
    The number of group nodes in each availability zone must not exceed the size of the reserved instance pools in those zones.
    
    {% endnote %}

1. [Create](../kubernetes-cluster/kubernetes-cluster-create.md) a Managed Service for Kubernetes cluster.
1. Create a node group:

    {% list tabs group=instructions %}

    - CLI {#cli}

      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

      The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

      In the terminal, run this command:

      ```bash
      yc managed-kubernetes node-group create \
        --name k8s-reserved-ng \
        --cluster-id <cluster_ID> \
        --platform-id standard-v4a \
        --cores 4 \
        --memory 8 \
        --disk-size 64 \
        --disk-type network-ssd \
        --fixed-size 2 \
        --location zone=ru-central1-a,subnet-id=<subnet_ID> \
        --network-interface security-group-ids=[<security_group_IDs>] \
        --reserved-instance-pool-id <reserved_instance_pool_ID>
      ```
      
      Where:
      * `--cluster-id`: [Cluster ID](../kubernetes-cluster/kubernetes-cluster-list.md).
      * `--location`: Availability zone and subnet [ID](../../../vpc/operations/subnet-get-info.md).
      * `--network-interface security-group-ids`: Security group [IDs](../../../vpc/operations/security-group-get-info.md).
      * `--reserved-instance-pool-id`: Reserved instance pool [ID](../../../compute/cli-ref/reserved-instance-pool/list.md).

      For more information about this command, see the [CLI reference](../../cli-ref/node-group/create.md).

    - Terraform {#tf}

      If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
      
      
      To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

      1. In the configuration file, describe the node group parameters:

          ```hcl
          resource "yandex_kubernetes_node_group" "k8s-reserved-ng" {
            cluster_id = "<cluster_ID>"
            name       = "k8s-reserved-ng"
          
            instance_template {
              platform_id = "standard-v4a"
              reserved_instance_pool_id = "<reserved_instance_pool_ID>"
          
              resources {
                cores  = 4
                memory = 8
              }
          
              boot_disk {
                size = 64
                type = "network-ssd"
              }
          
              network_interface {
                subnet_ids = ["<subnet_ID>"]
                security_group_ids = ["<security_group_IDs>"]
                nat        = true
              }
            }
          
            scale_policy {
              fixed_scale {
                size = 2
              }
            }
          
            allocation_policy {
              location {
                zone = "ru-central1-a"
              }
            }
          }
          ```
          
          Where:
          * `cluster_id`: [Cluster ID](../kubernetes-cluster/kubernetes-cluster-list.md).
          * `subnet_ids`: [Subnet](../../../vpc/operations/subnet-get-info.md) ID.
          * `security_group_ids`: Security group [IDs](../../../vpc/operations/security-group-get-info.md).
          * `reserved_instance_pool_id`: Reserved instance pool [ID](../../../compute/cli-ref/reserved-instance-pool/list.md).

      1. Create a node group:

          1. In the terminal, navigate to the configuration file directory.
          1. Make sure the configuration is correct using this command:
          
             ```bash
             terraform validate
             ```
          
             If the configuration is valid, you will get this message:
          
             ```bash
             Success! The configuration is valid.
             ```
          
          1. Run this command:
          
             ```bash
             terraform plan
             ```
          
             You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
          1. Apply the configuration changes:
          
             ```bash
             terraform apply
             ```
          
          1. Type `yes` and press **Enter** to confirm the changes.

      For more information about `yandex_kubernetes_node_group`, see [this Terraform reference](../../../terraform/resources/kubernetes_node_group.md).

    {% endlist %}

## Creating a node group in three availability zones with nodes from reserved instance pools in each zone {#multi-zone}

1. [Create](../../../compute/operations/reserved-pools/create-reserved-pool.md) reserved instance pools in three availability zones, using a configuration you want to use for Managed Service for Kubernetes cluster nodes.

    {% note info %}
    
    Make sure the following properties are identical in the node group and reserved instance pool configurations:
    * [Platform](../../../compute/concepts/vm-platforms.md)
    * Number of vCPUs
    * Amount of RAM
    * [Availability zone](../../../overview/concepts/geo-scope.md)
    
    The number of group nodes in each availability zone must not exceed the size of the reserved instance pools in those zones.
    
    {% endnote %}

1. [Create](../kubernetes-cluster/kubernetes-cluster-create.md) a Managed Service for Kubernetes cluster.
1. Create a node group:

    {% note tip %}
    
    Reserved instance pools are created in a specific availability zone. To automate the distribution of multi-zone group nodes across reserved instance pools of a specific availability zone, use the [node template variables](../../concepts/node-group/variables-in-the-template.md). 
    
    {% endnote %}

    {% list tabs group=instructions %}

    - CLI {#cli}

      If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

      The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

      In the terminal, run this command:

      ```bash
      yc managed-kubernetes node-group create \
        --name k8s-multizone-reserved-ng \
        --cluster-id <cluster_ID> \
        --platform-id standard-v4a \
        --cores 4 \
        --memory 8 \
        --disk-size 64 \
        --disk-type network-ssd \
        --fixed-size 3 \
        --location zone=ru-central1-a,subnet-id=<subnet_ID_in_zone_a> \
        --location zone=ru-central1-b,subnet-id=<subnet_ID_in_zone_b> \
        --location zone=ru-central1-d,subnet-id=<subnet_ID_in_zone_d> \
        --network-interface security-group-ids=[<security_group_IDs>] \
        --reserved-instance-pool-id '{pool_{instance.zone_id}}' \
        --variables \
      pool_ru-central1-a=<pool_ID_in_zone_a>,\
      pool_ru-central1-b=<pool_ID_in_zone_b>,\
      pool_ru-central1-d=<pool_ID_in_zone_d>
      ```
      
      Where:
      * `--cluster-id`: [Cluster ID](../kubernetes-cluster/kubernetes-cluster-list.md).
      * `--location`: Availability zones and their relevant subnet [IDs](../../../vpc/operations/subnet-get-info.md).
      * `--network-interface security-group-ids`: Security group [IDs](../../../vpc/operations/security-group-get-info.md).
      * `--reserved-instance-pool-id`: Reserved instance pool [IDs](../../../compute/cli-ref/reserved-instance-pool/list.md) you will get as a result of substituting the `instance.zone_id` [system variable](../../../compute/concepts/instance-groups/variables-in-the-template.md#first-stage) (availability zone of a specific node) and the [user-defined variables](../../../compute/concepts/instance-groups/variables-in-the-template.md#second-stage) specified in the `--variables` parameter.
      * `--variables`: User-defined variables with IDs of reserved instance pools in different availability zones.

      For more information about this command, see the [CLI reference](../../cli-ref/node-group/create.md).

    - Terraform {#tf}

      If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
      
      
      To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

      1. In the configuration file, describe the node group parameters:

          ```hcl
          resource "yandex_kubernetes_node_group" "k8s-multizone-reserved-ng" {
            cluster_id = "<cluster_ID>"
            name       = "k8s-multizone-reserved-ng"
          
            # Variables for reserved instance pools
            variables = {
              pool_ru-central1-a = "<reserved_instance_pool_ID_in_zone_a>"
              pool_ru-central1-b = "<reserved_instance_pool_ID_in_zone_b>"
              pool_ru-central1-d = "<reserved_instance_pool_ID_in_zone_d>"
            }
          
            instance_template {
              name = "test-{instance.zone_id}-{instance.index}"
              # instance.zone_id: System variable with the zone ID
              reserved_instance_pool_id = "{pool_{instance.zone_id}}"
              platform_id = "standard-v4a"
          
              resources {
                cores = 4
                memory = 8
              }
          
              boot_disk {
                size = 64
                type = "network-ssd"
              }
          
              network_interface {
                nat = true
                subnet_ids = [
                  "<subnet_ID_in_zone_a>",
                  "<subnet_ID_in_zone_b>",
                  "<subnet_ID_in_zone_d>"
                ]
                security_group_ids = ["<security_group_IDs>"]
              }
            }
          
            scale_policy {
              fixed_scale {
                size = 3
              }
            }
          
            allocation_policy {
              location {
                zone = "ru-central1-a"
              }
          
              location {
                zone = "ru-central1-b"
              }
          
              location {
                zone = "ru-central1-d"
              }
            }
          }
          ```
          
          Where:
          * `cluster_id`: [Cluster ID](../kubernetes-cluster/kubernetes-cluster-list.md).
          * `variables`: [User-defined variables](../../../compute/concepts/instance-groups/variables-in-the-template.md#second-stage) with [IDs](../../../compute/cli-ref/reserved-instance-pool/list.md) of reserved instance pools in different availability zones.
          * `name`: Node name in the group, generated using the following [system variables](../../../compute/concepts/instance-groups/variables-in-the-template.md#first-stage): `instance.zone_id` (the node’s availability zone) and `instance.index` (unique node number in the group, starting from 1).
          * `reserved_instance_pool_id`: Reserved instance pool IDs you will get as a result of substituting the `instance.zone_id` system variable and the user-defined variables specified in the `variables` parameter.
          * `subnet_ids`: Subnet [IDs](../../../vpc/operations/subnet-get-info.md).
          * `security_group_ids`: Security group [IDs](../../../vpc/operations/security-group-get-info.md).

      1. Create a node group:

          1. In the terminal, navigate to the configuration file directory.
          1. Make sure the configuration is correct using this command:
          
             ```bash
             terraform validate
             ```
          
             If the configuration is valid, you will get this message:
          
             ```bash
             Success! The configuration is valid.
             ```
          
          1. Run this command:
          
             ```bash
             terraform plan
             ```
          
             You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
          1. Apply the configuration changes:
          
             ```bash
             terraform apply
             ```
          
          1. Type `yes` and press **Enter** to confirm the changes.

      For more information about `yandex_kubernetes_node_group`, see [this Terraform reference](../../../terraform/resources/kubernetes_node_group.md).

    {% endlist %}

### Useful links {#see-also}

* [Reserved instance pools for Yandex Managed Service for Kubernetes node groups](../../concepts/node-group/reserved-pools.md)
* [Variables in a Yandex Managed Service for Kubernetes node template](../../concepts/node-group/variables-in-the-template.md)
* [Reserved instance pools in Compute Cloud](../../../compute/concepts/reserved-pools.md)
* [Working with reserved instance pools](../../../compute/operations/index.md#reserved-pools)
* [Variables in an instance template](../../../compute/concepts/instance-groups/variables-in-the-template.md)
* [Creating a node group](node-group-create.md)