Manually live migrate VMs


To move sole-tenant VMs to a different node or node group, you can manually initiate a live migration. You can also manually initiate a live migration to move a multi-tenant VM into sole-tenancy. For information about how to move a VM out of sole-tenancy, see Move a VM out of sole-tenancy.

Before you begin

  • If you haven't already, set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine as follows.

    Select the tab for how you plan to use the samples on this page:

    gcloud

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. Set a default region and zone.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init

API rate limits

Manual live migration requests are categorized in the Queries API rate limit.

Manually live migrate VMs into or within sole-tenancy

To manually live migrate VMs into or within sole-tenancy, use the gcloud CLI or REST.

If the destination of the VM is a node group, Compute Engine selects the node within the group that has both enough space for the VM and the least amount of spare capacity.

You cannot perform live migration between projects while using shared sole-tenant node groups.

Permissions required for this task

To perform this task, you must have the following permissions:

  • compute.instances.update permissions on the VM.

gcloud

To manually live migrate VMs into or within sole-tenancy, use the following gcloud compute instances update command:

gcloud compute instances update VM_NAME \
    ( --node=NODE \
      --node-group=NODE_GROUP \
      --node-affinity-file=NODE_AFFINITY_FILE )

Replace the following:

  • VM_NAME: the name of the VM to update the node affinity labels for.

Replace exactly one of the following:

  • NODE: the name of the node to live migrate the VM to.

  • NODE_GROUP: the name of the node group to live migrate the VM to.

  • NODE_AFFINITY_FILE: the name of a JSON file containing a configuration of nodes on which this VM could be scheduled. For more information, see Configure node affinity labels.

REST

To manually live migrate VMs into or within sole-tenancy, use the following instances.update method:

PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME

{
  ...
  "scheduling": {
    "nodeAffinities": [
      {
        "key": "NODE_AFFINITY_LABEL_KEY",
        "operator": "IN",
        "values": [
          "[NODE_AFFINITY_LABEL_VALUE]"
        ]
      }
    ]
  }
  ...
}

Replace the following:

  • PROJECT_ID: the ID of the project that has the VM to update the node affinity labels for.

  • ZONE: the zone of the VM to update the node affinity labels for.

  • VM_NAME: the name of the VM to update the node affinity labels for.

  • NODE_AFFINITY_LABEL_KEY: one of the following strings that specifies whether to live migrate the VM to a node group or node:

    VM destination Key to specify
    Node group compute.googleapis.com/node-group-name
    Node compute.googleapis.com/node-name
  • NODE_AFFINITY_LABEL_VALUE: the name of the node group or node to live migrate the VM to.

What's next