Migrating Valkey™ cluster hosts to a different availability zone
Note
Clusters with hosts residing in the ru-central1-d availability zone do not support:
- Intel Broadwell
- Local SSD storage if using Intel Cascade Lake
Yandex Managed Service for Valkey™ cluster hosts reside in Yandex Cloud availability zones. 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:
-
Create a subnet in your target availability zone.
-
If your cluster uses the
b2.mediumorb3-c1-m4host class, change it. 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.
-
Add a host to your cluster:
Management consoleCLITerraformREST APIgRPC API-
Go to Yandex Managed Service for Valkey™.
-
Click the cluster name and navigate to the Hosts tab.
-
Click
Create host. -
Specify the following host settings:
- Availability zone to move your hosts to.
- New subnet.
- Select Public access to make the host accessible from outside Yandex Cloud, if required.
-
Click Save.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the
yc config set folder-id <folder_ID>command. You can also set a different folder for any specific command using the--folder-nameor--folder-idparameter.Run this command:
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.
In the
zone-idargument, specify the target availability zone for your hosts.-
Add a host manifest to the Terraform configuration file describing your infrastructure:
resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" { ... host { zone = "<availability_zone>" subnet_id = "<new_subnet_ID>" assign_public_ip = <allow_public_access_to_host> } }In the
zoneattribute, specify the target availability zone for your hosts. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.AddHosts method, e.g., via the following cURL
request: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
hostSpecssets the host parameters:zoneId: Availability zone.subnetId: Subnet ID. Specify it if the selected availability zone has two or more subnets.shardName: Shard name for the host. Only used if cluster sharding is enabled.replicaPriority: Host priority for promotion to master if the primary master fails.assignPublicIp: Internet access to the host via a public IP address,trueorfalse. You can only enable public access if your cluster supports TLS.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
-
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 your source availability zone.
To get the FQDN, request the list of hosts in the cluster:
yc managed-redis host list --cluster-name <cluster_name>You will see the FQDN under
NAMEin the command output. -
Delete the hosts in the source availability zone:
Management consoleCLITerraformREST APIgRPC API- Go to Yandex Managed Service for Valkey™.
- Click the cluster name and select the Hosts tab.
- Click
in the host row, select Delete, and confirm the deletion.
Run the following command for each host:
yc managed-redis host delete <host_FQDN> --cluster-name <cluster_name>-
In your Terraform infrastructure configuration file, delete the
hostresource sections with the source availability zone from your cluster description. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Type
yesand press Enter.-
Run this command to view the planned changes:
terraform planIf 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.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.DeleteHosts method, e.g., via the following cURL
request: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
hostNamesis the name of the host to delete. To find out the name, get a list of hosts in the cluster.You can get the cluster ID with a list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and save it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.DeleteHosts method, e.g., via the following gRPCurl
request: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.DeleteHostsWhere
host_namesis the name of the host to delete. To find out the name, get the list of hosts in the cluster.You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
Wait for the cluster state to change to Alive. In the management console, navigate to the folder dashboard and select Yandex Managed Service for Valkey™. You can see the cluster state in the Availability column.