[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Valkey™](../index.md) > [Step-by-step guides](index.md) > Clusters > Migrating hosts to a different availability zone

# Migrating Valkey™ cluster hosts to a different availability zone


{% note info %}

Clusters with hosts residing in the `ru-central1-d` [availability zone](../../overview/concepts/geo-scope.md) do not support:

- Intel Broadwell
- Local SSD storage if using Intel Cascade Lake

{% endnote %}


Yandex Managed Service for Valkey™ cluster hosts reside in Yandex Cloud [availability zones](../../overview/concepts/geo-scope.md). To migrate hosts from one availability zone to another, add hosts in the target availability zone to the cluster and delete hosts in the source availability zone:

1. [Create a subnet](../../vpc/operations/subnet-create.md) in your target availability zone.
1. If your cluster uses the `b2.medium` or `b3-c1-m4` [host class](../concepts/instance-types.md#available-flavors), [change it](update.md#change-resource-preset). Otherwise, you will not be able to add hosts to the cluster and perform migration.

   The cluster is unavailable for about five to seven minutes after changing the host class.

   You can revert to the previous host class after the migration is complete.

1. Add a host to your cluster:

   {% list tabs group=instructions %}

   - Management console {#console}

      1. Navigate to **Yandex Managed Service for&nbsp;Valkey™**.
      1. Click the cluster name and navigate to the **Hosts** tab.
      1. Click ![image](../../_assets/console-icons/plus.svg) **Create host**.
      1. Specify the following host settings:

         * Target availability zone for your hosts.
         * New subnet.
         * To make the host accessible from outside Yandex Cloud, select **Public access**.

      1. Click **Save**.

   - 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.

      Run this command:

      ```bash
      yc managed-redis host add \
         --cluster-name <cluster_name> \
         --host zone-id=<availability_zone>,`
               `subnet-id=<new_subnet_ID>,`
               `assign-public-ip=<allow_public_access_to_host>
      ```

      You can get the cluster name with the [list of clusters in the folder](cluster-list.md#list-clusters).

      In the `zone-id` argument, specify the target availability zone for your hosts.

   - Terraform {#tf}

      1. Add the host manifest to the Terraform configuration file describing your infrastructure:

         ```hcl
         resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
           ...
           hosts = {
             ...
             "<new_host_name>" = {
               zone             = "<availability_zone>"
               subnet_id        = "<new_subnet_ID>"
               assign_public_ip = <allow_public_access_to_host>
             }
           }
         }
         ```

         In the `zone` parameter, specify the target availability zone for your hosts.

      1. Make sure the settings are correct.

         1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
         1. Run this command:
         
            ```bash
            terraform validate
            ```
         
            Terraform will show any errors found in your configuration files.

      1. Confirm updating the resources.

         1. Run this command to view the planned changes:
         
            ```bash
            terraform plan
            ```
         
            If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
         
         1. If everything looks correct, apply the changes:
            1. Run this command:
         
               ```bash
               terraform apply
               ```
         
            1. Confirm updating the resources.
            1. Wait for the operation to complete.

   - REST API {#api}

       1. [Get an IAM token for API authentication](../api-ref/authentication.md) and place it in an environment variable:
       
           ```bash
           export IAM_TOKEN="<IAM_token>"
           ```
       
       1. Call the [Cluster.AddHosts](../api-ref/Cluster/addHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:
       
           
           ```bash
           curl \
               --request POST \
               --header "Authorization: Bearer $IAM_TOKEN" \
               --header "Content-Type: application/json" \
               --url 'https://mdb.api.cloud.yandex.net/managed-redis/v1/clusters/<cluster_ID>/hosts:batchCreate' \
               --data '{
                         "hostSpecs": [
                           {
                             "zoneId": "<availability_zone>",
                             "subnetId": "<subnet_ID>",
                             "shardName": "<shard_name>",
                             "replicaPriority": "<host_priority>",
                             "assignPublicIp": <allow_public_access_to_host>
                           }
                         ]
                       }'
           ```
       
       
           Where `hostSpecs` sets the host parameters:
       
           * `zoneId`: [Availability zone](../../overview/concepts/geo-scope.md).
           * `subnetId`: [Subnet ID](../../vpc/concepts/network.md#subnet). Specify it if the selected availability zone has two or more subnets.
           * `shardName`: Shard name for the host. Only used if [cluster sharding](../concepts/sharding.md) is enabled.
           * `replicaPriority`: Host priority for master promotion during [failover](../concepts/replication.md#master-failover).
           * `assignPublicIp`: Internet access to the host via a public IP address, `true` or `false`. You can only enable public access if your cluster supports TLS.
       
           You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).
       
       1. Check the [server response](../api-ref/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

   - gRPC API {#grpc-api}

       1. [Get an IAM token for API authentication](../api-ref/authentication.md) and place it in an environment variable:
       
           ```bash
           export IAM_TOKEN="<IAM_token>"
           ```
       
       1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
          
          ```bash
          cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
          ```
          
          Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
       
       1. Call the [ClusterService.AddHosts](../api-ref/grpc/Cluster/addHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:
       
           
           ```bash
           grpcurl \
               -format json \
               -import-path ~/cloudapi/ \
               -import-path ~/cloudapi/third_party/googleapis/ \
               -proto ~/cloudapi/yandex/cloud/mdb/redis/v1/cluster_service.proto \
               -rpc-header "Authorization: Bearer $IAM_TOKEN" \
               -d '{
                     "cluster_id": "<cluster_ID>",
                     "host_specs": [
                       {
                         "zone_id": "<availability_zone>",
                         "subnet_id": "<subnet_ID>",
                         "shard_name": "<shard_name>",
                         "replica_priority": "<host_priority>",
                         "assign_public_ip": <allow_public_access_to_host>
                       }
                     ] 
                   }' \
               mdb.api.cloud.yandex.net:443 \
               yandex.cloud.mdb.redis.v1.ClusterService.AddHosts
           ```
       
       
           Where `host_specs` sets the host parameters:
       
           * `zone_id`: [Availability zone](../../overview/concepts/geo-scope.md).
           * `subnet_id`: [Subnet ID](../../vpc/concepts/network.md#subnet). Specify it if the selected availability zone has two or more subnets.
           * `shard_name`: Shard name for the host. Only used if [cluster sharding](../concepts/sharding.md) is enabled.
           * `replica_priority`: Host priority for master promotion during [failover](../concepts/replication.md#master-failover).
           * `assign_public_ip`: Internet access to the host via a public IP address, `true` or `false`. You can only enable public access if your cluster supports TLS.
       
           You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).
       
       1. Check the [server response](../api-ref/grpc/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

   {% endlist %}

1. To connect to the database after migration, specify the new host’s FQDN in your backend or client, e.g., in your application code or graphical IDE. Delete the original host's FQDN in the source availability zone.

   You can get this FQDN from the list of hosts in your cluster.

   ```bash
   yc managed-redis host list --cluster-name <cluster_name>
   ```

   You will see the FQDN under `NAME` in the command output.

1. Delete the hosts in the source availability zone:

   {% list tabs group=instructions %}

   - Management console {#console}

      1. Navigate to **Yandex Managed Service for&nbsp;Valkey™**.
      1. Click the name of your cluster and select the **Hosts** tab.
      1. Click ![image](../../_assets/console-icons/ellipsis.svg) in the host row, select **Delete**, and confirm the deletion.

   - CLI {#cli}

      Run the following command for each host:

      ```bash
      yc managed-redis host delete <host_FQDN> --cluster-name <cluster_name>
      ```

   - Terraform {#tf}

      1. In your Terraform infrastructure configuration file, delete the hosts with the source availability zone from the `hosts` section in the cluster description.
      1. Make sure the settings are correct.

         1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
         1. Run this command:
         
            ```bash
            terraform validate
            ```
         
            Terraform will show any errors found in your configuration files.

      1. Type `yes` and press **Enter**.

         1. Run this command to view the planned changes:
         
            ```bash
            terraform plan
            ```
         
            If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
         
         1. If everything looks correct, apply the changes:
            1. Run this command:
         
               ```bash
               terraform apply
               ```
         
            1. Confirm updating the resources.
            1. Wait for the operation to complete.

   - REST API {#api}

       1. [Get an IAM token for API authentication](../api-ref/authentication.md) and place it in an environment variable:
       
           ```bash
           export IAM_TOKEN="<IAM_token>"
           ```
       
       1. Call the [Cluster.DeleteHosts](../api-ref/Cluster/deleteHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:
       
           ```bash
           curl \
               --request POST \
               --header "Authorization: Bearer $IAM_TOKEN" \
               --header "Content-Type: application/json" \
               --url 'https://mdb.api.cloud.yandex.net/managed-redis/v1/clusters/<cluster_ID>/hosts:batchDelete' \
               --data '{
                         "hostNames": [ "<host_name>" ]
                       }'
           ```
       
           Where `hostNames` is the name of the host to delete. To find out the name, [get the list of hosts in the cluster](hosts.md#list).
       
           You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).
       
       1. Check the [server response](../api-ref/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

   - gRPC API {#grpc-api}

       1. [Get an IAM token for API authentication](../api-ref/authentication.md) and place it in an environment variable:
       
           ```bash
           export IAM_TOKEN="<IAM_token>"
           ```
       
       1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
          
          ```bash
          cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
          ```
          
          Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
       
       1. Call the [ClusterService.DeleteHosts](../api-ref/grpc/Cluster/deleteHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:
       
           ```bash
           grpcurl \
               -format json \
               -import-path ~/cloudapi/ \
               -import-path ~/cloudapi/third_party/googleapis/ \
               -proto ~/cloudapi/yandex/cloud/mdb/redis/v1/cluster_service.proto \
               -rpc-header "Authorization: Bearer $IAM_TOKEN" \
               -d '{
                     "cluster_id": "<cluster_ID>",
                     "host_names": [ "<host_name>" ]
                   }' \
               mdb.api.cloud.yandex.net:443 \
               yandex.cloud.mdb.redis.v1.ClusterService.DeleteHosts
           ```
       
           Where `host_names` is the name of the host to delete. To find out the name, [get the list of hosts in the cluster](hosts.md#list).
       
           You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).
       
       1. Check the [server response](../api-ref/grpc/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

   {% endlist %}

1. Wait for the cluster state to change to **Alive**. In the management console, navigate to the folder dashboard and select **Yandex Managed Service for&nbsp;Valkey™**. You can check the cluster state in the **Availability** column.