[Yandex Cloud documentation](../../../index.md) > [Yandex Managed Service for Kubernetes](../../index.md) > [Concepts](../index.md) > Node group > Variables in a node template

# Variables in a Yandex Managed Service for Kubernetes node template

Managed Service for Kubernetes creates [groups of same-type cluster nodes](../index.md#node-group) from a template. To use different specifications for such nodes, use the substitution of template variables.

[System](../../../compute/concepts/instance-groups/variables-in-the-template.md#first-stage) and [user-defined](../../../compute/concepts/instance-groups/variables-in-the-template.md#second-stage) variables are supported.

For more information about variables and their substitution steps, see [Variables in an instance template](../../../compute/concepts/instance-groups/variables-in-the-template.md).

For example, you can use variables to [create](../../operations/node-group/node-group-create-in-instance-pool.md) a multi-zone group of nodes from reserved instance pools located in different [availability zones](../../../overview/concepts/geo-scope.md).

You can use variables via the [CLI](../../cli-ref/node-group/create.md), [Terraform](../../../terraform/resources/kubernetes_node_group.md), and [API](../../managed-kubernetes/api-ref/NodeGroup/create.md).

## Examples {#examples}

In this example, we will create a node group in three availability zones with one node from reserved instance pools per zone.

{% list tabs group=instructions %}

- CLI {#cli}

  ```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](../../operations/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.

- Terraform {#tf}

  ```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](../../operations/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).

{% endlist %}

See [Reserved instance pools for node groups](reserved-pools.md#examples) for examples for a group of nodes from a reserved instance pool in a single availability zone.

### Useful links {#see-also}

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