If your virtual machine (VM) instance doesn't have attached Local SSD and is not part of a managed instance group (MIG), you can change the machine type of your instance after stopping it.
If your existing machine type is not a good fit for the workloads you run on your VM, change the machine type of that VM. For example, you can start a VM with a smaller machine type during setup, development, and testing and change the VM to use a larger machine type when you are ready for production workloads.
You can use this procedure in the following situations:
n2-highcpu-4
to n2-standard-4
.c3d-standard-30
to c3d-highmem-30
.n2-standard-4
to c2-standard-8
.n1-highmem-4
to n2d-standard-16
.If you want to change the machine type for a VM that uses a first or second generation machine series (N1, N2, M1, etc.) to a machine type for a third generation or later machine series (M3, C3, N4, etc.), you must use the procedure documented in Move your workload to a new compute instance.
You can change the machine type without affecting the following resources:
To change the machine type of VMs within a MIG, see Automatically apply VM configuration updates in a MIG.
Caution:udev
to change the network device name. The change in the network device name might cause startup issues.Select the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
JavaTo use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
PythonTo use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
RESTTo 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.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
To get the permissions that you need to change the machine type of a VM, ask your administrator to grant you the following IAM roles on the project:
roles/compute.instanceAdmin.v1
)roles/iam.serviceAccountUser
)For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to change the machine type of a VM. To see the exact permissions that are required, expand the Required permissions section:
Required permissionsThe following permissions are required to change the machine type of a VM:
compute.instances.setMachineType
on VM compute.instances.start
on VM compute.instances.stop
on VMYou might also be able to get these permissions with custom roles or other predefined roles.
LimitationsEach machine type is billed at a different rate, so make sure you understand the pricing implications of changing machine types. For example, an e2-standard-2
machine type costs more than an e2-micro
machine type.
Changing a machine type might also affect the sustained use discounts for that VM. Sustained use discounts are calculated separately for different categories in the same region. If you change machine types so that the new machine type is in a different category, the subsequent running time of the VM counts toward the sustained use discount of the new category.
For example, assume you have a VM with n2-standard-2
machine type running for half a month. You then decide to change the machine type to m1-ultramem-40
. Once you make that change, Compute Engine starts counting the running time of the VM towards the sustained use discount of the memory-optimized vCPU and memory category.
On your bill, you would see a sustained use discount applied to the n2-standard-2
machine type from before you made the machine type change, and a separate sustained use discount for m1-ultramem-40
, if your VM remains running on m1-ultramem-40
for at least a 25% of the rest of the month.
If you move from a machine type with more resources to a machine type with fewer resources, such as moving from a e2-standard-8
machine type to a e2-standard-2
, you could run into hardware resource issues or performance limitations because smaller machine types are less powerful than larger machine types. Make sure that your new machine type is able to support any applications or services that are running on your current VM, or that you update your services and applications to run on the smaller machine types.
Review the rightsizing recommendations before changing the machine type. For information about Compute Engine sizing recommendations, see Applying machine type recommendations for VM instances.
Best practicesHere are some best practices to help you successfully change the VM machine type.
Make regular backups of your Persistent Disk data using snapshots. Consider taking a snapshot of your Persistent Disk data before you change the machine type. If you want to make sure the new machine type is able to support the data on the existing VM, you can take a Persistent Disk snapshot and use it to start a second VM with the new machine type to confirm that the VM starts up successfully.
Add additional disks to the /etc/fstab
file. If you have additional disks attached to your VM, make sure they are added to the /etc/fstab
file so that they are automatically mounted when the VM reboots.
Create a reservation before changing the machine type. To avoid errors related to resource availability, create Compute Engine reservations for the new machine types when they are available to reserve them within a zone. Reservations help ensure that the resources are available when you need them.
To create a reservation, complete the following steps:
Create a reservation (or identify existing reservations) with identical properties as the planned VMs. The reservation's VM count needs to be equal to or greater than the number of VMs that you want to change. Optionally, to prevent other VMs from consuming this reservation, use the specificReservationRequired
option.
Verify that the planned VMs will be able to consume the reservation:
You can only change the machine type of a stopped VM. A VM is considered stopped only when the VM is in the
TERMINATED
state. You can't change the machine type of a running VM.
If you are upgrading your machine type to the latest generation, review Evaluate VM migration options before proceeding.
Caution: If you don't have reservations for the new machine types, changing the machine type can result in resource availability errors. Resource availability errors are more likely for uncommon resource types and large requests, and can be avoided by requesting different resources, requesting fewer resources at a time, or using reservations. For more information, see resource availability errors. ConsoleIn the Google Cloud console, go to the VM instances page.
In the Name column, click the name of the VM for which you want to change machine type.
From the VM instance details page, complete the following steps:
In the Machine configuration section, select the machine type that you want to use, or create a custom machine type.
To save your changes, click Save.
Restart the VM.
Stop the VM by using the gcloud compute instances stop
command:
gcloud compute instances stop VM_NAME
Replace VM_NAME
with the VM containing the machine type to change.
Change the machine type by using the gcloud compute instances set-machine-type
command:
gcloud compute instances set-machine-type VM_NAME \ --machine-type NEW_MACHINE_TYPE
Replace NEW_MACHINE_TYPE
with the new machine type for the VM. The machine type can be one of the following:
For example: e2-standard-2
For example, you can specify --machine-type e2-custom-4-2048
to set a custom machine type that has 4 vCPUs and 2 GB of memory.
Start the VM by using the gcloud compute instances start
command:
gcloud compute instances start VM_NAME
Replace VM_NAME
with the name of the VM that you changed.
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python PythonBefore trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
RESTStop the VM by using the instances.stop
method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop
Replace the following:
PROJECT_ID
: the project ID
ZONE
: the zone containing the VM
VM_NAME
: the VM containing the machine type to change
Change the machine type by using the instances.setMachineType
method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setMachineType
In the body of the request, provide the updated machineType
:
{ machineType: "zones/MACHINE_TYPE_ZONE/machineTypes/NEW_MACHINE_TYPE" }
Replace the following:
MACHINE_TYPE_ZONE
: the zone containing the machine type
NEW_MACHINE_TYPE
: the new machine type for the VM
The machine type can be one of the following:
For example: e2-standard-2
For example, you can specify --machine-type e2-custom-4-2048
to set a custom machine type that has 4 vCPUs and 2 GB of memory.
Start the VM by using the instances.start
method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/start
Replace the following:
PROJECT_ID
: the project IDZONE
: the zone containing the VMVM_NAME
: the name of the VM that you changedRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4