Moving a subnet to a different availability zone
You can move a subnet to a different availability zone. You can only move an empty subnet containing no VMs or other resources.
Make sure the subnet does not include addresses of target load balancer groups either. They prevent migration. Remove unused target groups or individual addresses.
To move a subnet to a different availability zone:
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI subnet move command:
yc vpc subnet relocate --help
-
In the default folder, find the ID of the subnet you need to move:
yc vpc subnet list
Result:
+----------------------+----------+----------------------+----------------+---------------+------------------+ | ID | NAME | NETWORK ID | ROUTE TABLE ID | ZONE | RANGE | +----------------------+----------+----------------------+----------------+---------------+------------------+ | e9bcd5mq43cn******** | subnet-a | encb4ubvmief******** | | ru-central1-a | [10.1.0.0/16] | | e2llon52hhss******** | subnet-b | enc39op1vq9m******** | | ru-central1-b | [192.168.1.0/24] | | b0cscj0f9uq5******** | subnet-c | enc772aa2rgq******** | | ru-central1-c | [10.0.0.0/16] | +----------------------+----------+----------------------+----------------+---------------+------------------+
Note
Make sure a subnet you are moving has no VMs. If you need to move a subnet with VMs, first move all the VMs and then the subnet to a new availability zone.
-
Move the subnet:
yc vpc subnet relocate \ --id <subnet_ID> \ --destination-zone-id <availability_zone_ID>
Where:
-
--id
: ID of the subnet you need to move. -
--destination-zone-id
: ID of the availability zone to move the subnet to. The possible values are:ru-central1-a
ru-central1-b
ru-central1-c
ru-central1-d
Examples:
yc vpc subnet relocate \ --id e9bcd5mq43cn******** \ --destination-zone-id ru-central1-d
Result:
id: e9bcd5mq43cn******** folder_id: b1gt6g8ht345******** created_at: "2023-10-06T10:30:06Z" name: subnet-a network_id: encb4ubvmief******** zone_id: ru-central1-d v4_cidr_blocks: - 10.1.0.0/16 dhcp_options: {}
For more information about the
yc vpc subnet relocate
command, see the CLI reference. -
Use the relocate REST API method for the Subnet resource or the SubnetService/Relocate gRPC API call.
Request example
To run the sample, install cURL
-
Get an IAM token for authentication in the API.
-
Save the token to a variable.
export IAM_TOKEN=<obtained_IAM_token>
-
Prepare a
body.json
file with the request body, specifying the ID of the availability zone to move the subnet to:{ "destinationZoneId": "<availability_zone_ID>" }
-
Run the following query:
curl \ --request POST \ --header "Authorization: Bearer ${IAM_TOKEN}" \ --data "@<request_body_file>" \ https://vpc.api.cloud.yandex.net/vpc/v1/subnets/<subnet_ID>:relocate
Where:
<request_body_file>
: Path to the previously created request body file (body.json
).<subnet_ID>
: ID of the subnet to move to a new availability zone.
Note
Make sure a subnet you are moving has no VMs. If you need to move a subnet with VMs, first move all the VMs and then the subnet to a new availability zone.
Result:
{ "done": true, "metadata": { "@type": "type.googleapis.com/yandex.cloud.vpc.v1.RelocateSubnetMetadata", "subnetId": "b0cnd1srghnm********" }, "response": { "@type": "type.googleapis.com/yandex.cloud.vpc.v1.Subnet", "v4CidrBlocks": [ "192.168.3.0/24" ], "dhcpOptions": {}, "id": "b0cnd1srghnm********", "folderId": "b1gt6g8ht345********", "createdAt": "2023-10-06T10:30:06Z", "name": "subnet-c", "networkId": "enpv51f8lple********", "zoneId": "ru-central1-d" }, "id": "enpfitqeageu********", "description": "Relocate subnet to other zone", "createdAt": "2023-11-02T10:40:52.330608134Z", "createdBy": "ajeol2afu1js********", "modifiedAt": "2023-11-02T10:40:52.782965099Z" }