Compute Engine offers predefined machine types that you can use when you create a VM instance. A predefined machine type has a preset number of vCPUs and amount of memory and has a set price. If predefined VMs don't meet your needs, you can create a VM instance with custom virtualized hardware settings. Specifically, you can create a VM instance with a custom number of vCPUs and amount of memory, effectively using a custom machine type. Custom machine types are available for the following:
- General-purpose machine family for the N and E machine series only. You can create a custom VM on the N4, N4D, N4A, N2, N2D, E2, or N1 machine series.
- Accelerator-optimized machine family for the G2 machine series only.
Custom VMs are ideal in the following scenarios:
- Workloads that aren't a good fit for the predefined VM types.
- Workloads that require more processing power or more memory but don't need all the upgrades that the next-level machine type provides.
- Workloads that have per-CPU software license costs, where you can customize the number of vCPUs to avoid license costs for unused processing power or to match available software license counts.
Before you begin
- Read the machine families documentation.
-
If you haven't already, set up authentication.
Authentication verifies your identity for access to Google Cloud services and APIs. To run
code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
Terraform
To use the Terraform 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.
-
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.
Go
To use the Go 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.
-
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.
Java
To 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.
-
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.
Node.js
To use the Node.js 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.
-
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.
Python
To 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.
-
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.
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.
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.
-
Required roles
To get the permissions that
you need to create a VM with a custom machine type,
ask your administrator to grant you the
Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to create a VM with a custom machine type. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create a VM with a custom machine type:
-
To add extended memory to an existing VM:
compute.instances.setMachineTypeon the VM -
To create a VM with a custom machine type:
compute.instances.createon the project- To use a custom image to create the VM:
compute.images.useReadOnlyon the image - To use a snapshot to create the VM:
compute.snapshots.useReadOnlyon the snapshot - To use an instance template to create the VM:
compute.instanceTemplates.useReadOnlyon the instance template - To assign a legacy network to the VM:
compute.networks.useon the project - To specify a static IP address for the VM:
compute.addresses.useon the project - To assign an external IP address to the VM when using a legacy network:
compute.networks.useExternalIpon the project - To specify a subnet for the VM:
compute.subnetworks.useon the project or on the chosen subnet - To assign an external IP address to the VM when using a VPC network:
compute.subnetworks.useExternalIpon the project or on the chosen subnet - To set VM instance metadata for the VM:
compute.instances.setMetadataon the project - To set tags for the VM:
compute.instances.setTagson the VM - To set labels for the VM:
compute.instances.setLabelson the VM - To set a service account for the VM to use:
compute.instances.setServiceAccounton the VM - To create a new disk for the VM:
compute.disks.createon the project - To attach an existing disk in read-only or read-write mode:
compute.disks.useon the disk - To attach an existing disk in read-only mode:
compute.disks.useReadOnlyon the disk
You might also be able to get these permissions with custom roles or other predefined roles.
Limitations
- If your VM has Local SSD disks, you can't change the vCPU and memory configuration.
Extended memory is available on N4, N4A, N4D, N2, N2D, and N1 custom machine types. For the limits on extended memory, see Add extended memory to a machine type.
Predefined machine types, as well as G2 and E2 custom machine types, don't support extended memory.
Extended memory doesn't qualify for resource-based committed use discounts.
Each machine type has specific ranges and values for vCPUs and memory, as shown in the following table:
| Machine series | Min vCPUs | Max vCPUs | Allowed vCPUs | Min memory per vCPU (GB) | Max memory per vCPU (GB) | Step size (MB) | Extended memory |
|---|---|---|---|---|---|---|---|
| N4 | 2 | 80 | Any multiple of 2 | 2 | 8 | 256 | Yes |
| N4D | 2 | 96 | 2, 4, 8, 16, 32, 48, 64, 80, 96 | 0.5 | 8 | 256 | Yes |
| N4A | 1 | 64 | Any | 2 | 8 | 256 | Yes |
| N2 | 2 | 80 | Multiples of 2 (up to 32) or 4 (32 to 80) | 0.5 | 8 | 256 | Yes |
| N2D | 2 | 96 | 2, 4, 8, 16, 32, 48, 64, 80, 96 | 0.5 | 8 | 256 | Yes |
| N1 | 1 | 96 | 1 or any multiple of 2 | 0.9 (1 for 1 or 2 vCPUs) | 6.5 | 256 | Yes |
| E2 | 2 | 32 | Any multiple of 2 | 0.5 | 8 | 256 | No |
| E2 shared-core | 0.25 | 1 | 0.25, 0.5, 1 | 1 total | 8 (2 total for micro, 4 total for small, 8 total for medium) | 256 | No |
Express memory in GB or MB
For historical reasons, Google Cloud tools and documentation refer to machine type memory as decimal megabytes (MB) and gigabytes (GB). However, these units represent binary gibibytes (GiB) and mebibytes (MiB), where 1 GB is 230 bytes, or 1,024 MB.
When you configure memory for a custom machine type, the unit requirements and conversions depend on the tool that you use:
- In the Google Cloud console, you specify memory in GB. For example, if your system needs 1,024 MB of memory, select 1 GB in the Google Cloud console.
- In the Compute Engine API, you must provide memory in MB as an integer multiple of 256 MB (or 1,024 MB for G2 VMs). For example, if you try to provision 5 GB of memory by specifying 5,000 MB in an API request, the API returns an error because 5,000 isn't a multiple of 256 (5 GB is 5,120 MB).
- In the Google Cloud CLI, you can provide the total memory for a VM in GB or
MB:
- The
--custom-memoryflag defaults to GB if you omit the unit. To specify memory in MB, you must include theMBunit suffix. For example, if you want 2,048 MB (2 GB) of memory and specify the--custom-memory=2048flag without a unit, the gcloud CLI requests 2,048 GB of memory instead of 2,048 MB. - Unitless values passed to
--custom-memorymust be integers. To express 0.25 GB (256 MB) increments such as 5.75 GB, either convert the value to an integer in MB (--custom-memory=5888MB) or include theGBunit suffix (--custom-memory=5.75GB). - With the
--machine-typeflag, you must specify memory in MB as an integer without a unit suffix—for example,--machine-type=n2-custom-2-5120.
- The
Custom machine type pricing
Compute Engine charges for custom VMs based on the number of vCPUs and memory hours that the VM uses. This pricing model differs from how Compute Engine charges for predefined machine types. The on-demand prices for custom machine types include a 5% premium over the on-demand prices for predefined machine types.
When you use a custom machine type, any memory up to and including the default amount per vCPU is charged at the machine family custom machine type pricing. E2 custom machine and E2 shared-core custom machine types share the same pricing scheme.
If you use your commitments to run custom machine types, then Compute Engine charges a 5% premium over the commitment prices. Compute Engine charges this premium for the portion and duration of your commitment that you run these custom machine type VMs.
To view pricing information by machine series, see VM instance pricing.
Custom VMs are subject to the same 1-minute minimum charge as any other instance, but sustained use discounts for custom machine types are calculated differently. For more information, see sustained use discounts for custom VMs.
Extended memory pricing
Compute Engine charges extra for memory above the range maximum for the number of vCPUs configured as extended memory, based on the machine family extended custom memory pricing. The price for extended memory is higher than the price for memory below the range maximum.
Extended memory prices differ depending on the region. Instances running with extended memory are subject to the same 1-minute minimum charge as any other instance. Extended memory doesn't qualify for resource-based committed use discounts, but it does qualify for compute flexible committed use discounts and sustained use discounts.
Add extended memory to a machine type
Each custom machine type machine series has a default RAM maximum per vCPU. For some workloads, this default maximum might not be enough memory per vCPU. For a premium, you can get more memory per vCPU beyond the default maximum up to the machine series limit, which is called extended memory. The following table lists the vCPU and extended memory limits for each supported machine series:
| Machine series | vCPU limit | Memory limit |
|---|---|---|
| N4 | 80 | 640 GB |
| N4D | 96 | 768 GB |
| N4A | 64 | 512 GB |
| N2 | 80 | 864 GB |
| N2D | 96 | 768 GB |
| N1 | 96 | 624 GB |
For higher RAM-to-vCPU ratios, see also the memory-optimized machine types.
Determine whether you need extended memory
Certain workloads need more than the default amount of memory per vCPU to deliver optimum results. Workloads that are based on in-memory high-performance analytics databases, including relational and NoSQL databases such as Microsoft SQL Server, MongoDB, and Memcached or Redis, are in this category. The vCPU-based licensing of operating systems and software stacks also makes selecting an optimal VM memory configuration more challenging with predefined machine types. By using extended memory, you can add as much memory as your VMs need for the best price-performance ratio.
Create a VM with a custom machine type
Before you create a custom VM instance, read the custom specifications for creating this machine type.Console
In the Google Cloud console, go to the Create an instance page.
In the Machine configuration pane, do the following:
- Select the Region and Zone where you want to host the instance.
- Select the machine configuration for your instance:
- To create a general-purpose custom VM, select General purpose, and then in the Series section, select N4, N4A, N4D, N2, N2D, E2, or N1.
- To create a custom VM with attached GPUs, select GPUs, and then
do the following:
- In the GPU type list, select a GPU for the machine series
that you want to use:
- For G2 VMs, select NVIDIA L4.
- For N1 VMs, select NVIDIA T4, NVIDIA V100, or NVIDIA Tesla P4.
- In the Number of GPUs list, select the number of GPUs.
- In the GPU type list, select a GPU for the machine series
that you want to use:
- In the Machine type section, select Custom.
- To specify the number of vCPUs and the amount of memory for the instance, drag the Cores and Memory sliders or enter the values in the fields. The console displays an estimated cost for the instance as you change the number of vCPUs and amount of memory.
Optional: Specify other configuration options. For more information, see Configuration options during instance creation.
To create and start the instance, click Create.
gcloud
Create a custom machine type by using the
gcloud compute instances create
command with the
--machine-type flag:
gcloud compute instances create INSTANCE_NAME \
--zone=ZONE \
--machine-type=MACHINE_SERIES-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB
Replace the following:
INSTANCE_NAME: the name of the instance.ZONE: the zone where you want to create the instance.MACHINE_SERIES: the lowercase machine series, such asn4,n4d,n4a,n2,n2d,e2, org2. For N1, omitMACHINE_SERIES-and start withcustom-.NUMBER_OF_VCPUS: the number of vCPUs.AMOUNT_OF_MEMORY_MB: the total amount of memory in MB. This value must be an integer multiple of 256 MB (or 1,024 MB for G2 VMs).
To create a G2 VM with 4 vCPUs and 19 GB of memory in zone
us-central1-a, run the following command:
gcloud compute instances create example-instance \
--zone=us-central1-a \
--machine-type=g2-custom-4-19456 \
--maintenance-policy=TERMINATE
For G2 VMs, memory must be a multiple of 1,024 MB and within the supported memory range. For more information about creating G2 VMs, see Create a G2 or G4 instance.
The following example creates an N2 custom machine type with 48 vCPUs and
310 GB (317,440 MB) of memory in zone us-central1-a:
gcloud compute instances create example-instance \
--zone=us-central1-a \
--machine-type=n2-custom-48-317440
For supported machine series, such as N4 or N2, you can configure extended
memory, which lets you specify a higher amount of memory than the maximum
default ratio of memory to vCPUs. To configure extended memory, increase the
value of AMOUNT_OF_MEMORY_MB and append -ext to
the machine type name—for example, --machine-type=n2-custom-48-720896-ext.
Alternatively, you can specify a custom machine type by using the
--custom-cpu, --custom-memory, and --custom-vm-type flags (and
include the --custom-extensions flag if you're configuring extended
memory):
gcloud compute instances create INSTANCE_NAME \
--zone=ZONE \
--custom-cpu=NUMBER_OF_VCPUS \
--custom-memory=AMOUNT_OF_MEMORY \
--custom-vm-type=MACHINE_SERIES
Replace the following:
INSTANCE_NAME: the name of the instance.ZONE: the zone where you want to create the instance.NUMBER_OF_VCPUS: the number of vCPUs.AMOUNT_OF_MEMORY: the total amount of memory with a unit suffix (MBorGB), or in GB if you omit the unit.MACHINE_SERIES: the lowercase machine series, such asn4,n4d,n4a,n2,n2d,e2, orn1.
The following example creates an N2 custom machine type with 48 vCPUs and
310 GB of memory by using the --custom-cpu, --custom-memory, and
--custom-vm-type flags:
gcloud compute instances create example-instance \
--zone=us-central1-a \
--custom-cpu=48 \
--custom-memory=317440MB \
--custom-vm-type=n2
When you use the --custom-memory flag, specify the total amount of
memory in GB or in MB. Unitless values must be integers. To specify
increments of 0.25 GB (256 MB) for memory, either convert the total memory
to an integer in MB (--custom-memory=5888MB) or include the GB unit
suffix (--custom-memory=5.75GB).
For E2 shared-core custom machine types, use the
gcloud compute instances create
command and include the
shared-core machine size (micro, small, or medium):
gcloud compute instances create INSTANCE_NAME \
--zone=ZONE \
--machine-type=e2-custom-SHARED_CORE_SIZE-AMOUNT_OF_MEMORY_MB
Replace the following:
INSTANCE_NAME: the name of the instance.ZONE: the zone where you want to create the instance.SHARED_CORE_SIZE: the E2 shared-core size (micro,small, ormedium).AMOUNT_OF_MEMORY_MB: the total amount of memory in MB. This value must be an integer multiple of 256 MB within the allowed range for the shared-core size.
The following example creates an E2 shared-core small custom machine type
with 0.5 vCPU and 2.25 GB (2,304 MB) of memory:
gcloud compute instances create example-instance \
--zone=us-central1-a \
--machine-type=e2-custom-small-2304
Terraform
To generate the Terraform code, you can use the Equivalent code component in the Google Cloud console.- In the Google Cloud console, go to the VM instances page.
- Click Create instance.
- Specify the parameters you want.
- At the top or bottom of the page, click Equivalent code, and then click the Terraform tab to view the Terraform code.
Go
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
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 client libraries.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
Before 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 client libraries.
REST
To create an instance with a custom machine type, call the
instances.insert method
and specify the custom
machineType values
with memory in MB:
- For the N1 machine series, omit the series prefix and start with
custom-. - For E2 shared-core machine types, replace the vCPU count with
micro,small, ormedium. - To enable extended memory, append
-extto the machine type string.
The following example creates an N2 custom machine type with 16 vCPUs and 105 GB (107,520 MB) of memory:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
"name": "example-instance",
"machineType": "zones/ZONE/machineTypes/n2-custom-16-107520",
"disks": [
{
"boot": true,
"initializeParams": {
"diskSizeGb": "10",
"sourceImage": "projects/debian-cloud/global/images/family/debian-13"
}
}
],
"networkInterfaces": [
{
"network": "global/networks/default"
}
]
}
Replace the following:
PROJECT_ID: the ID of the project where you want to create the instance.ZONE: the zone where you want to create the instance.
You can similarly create Spot VMs and managed instance groups (MIGs) with custom machine types.
Add extended memory during instance creation
To create a VM instance with extended memory, do the following:Console
In the Google Cloud console, go to the Create an instance page.
In the Machine configuration pane, do the following:
- Select the Region and Zone where you want to host the VM.
- Select the machine configuration for your instance:
- To create a general-purpose custom VM, select General purpose, and then in the Series section, select N4, N4D, N4A, N2, N2D, or N1.
- To create an N1 custom VM with attached GPUs, select GPUs, and
then do the following:
- In the GPU type list, select NVIDIA T4, NVIDIA V100, or NVIDIA Tesla P4.
- In the Number of GPUs list, select the number of GPUs.
- In the Machine type section, select Custom.
- To specify the number of vCPUs, drag the Cores slider or enter the value in the field.
- To add extended memory, select Extend Memory. To specify the amount of memory for the machine type, drag the Memory slider or enter the value in the field. The console displays an estimated cost for the VM as you edit the number of vCPUs and amount of memory.
Optional: Specify other configuration options. For more information, see Configuration options during instance creation.
To create and start the VM, click Create.
gcloud
Create a custom machine type with extended memory by using the
gcloud compute instances create
command with the
--machine-type flag and the -ext suffix:
gcloud compute instances create INSTANCE_NAME \
--zone=ZONE \
--machine-type=MACHINE_SERIES-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB-ext
Replace the following:
INSTANCE_NAME: the name of the instance.ZONE: the zone where you want to create the instance.MACHINE_SERIES: the lowercase machine series that supports extended memory, such asn4,n4d,n4a,n2, orn2d. For N1, omitMACHINE_SERIES-and start withcustom-.NUMBER_OF_VCPUS: the number of vCPUs.AMOUNT_OF_MEMORY_MB: the total amount of memory in MB. This value must be an integer multiple of 256 MB.
The following example creates an N2 custom machine type with 2 vCPUs and
20 GB (20,480 MB) of extended memory in zone us-central1-a:
gcloud compute instances create example-instance \
--zone=us-central1-a \
--machine-type=n2-custom-2-20480-ext
Go
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
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 client libraries.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
Before 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 client libraries.
REST
To create an instance with extended memory, call the
instances.insert method
and append -ext to the machineType field to extend the memory up to the
limit for that machine series:
zones/ZONE/machineTypes/MACHINE_SERIES-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB-ext
Replace the following:
ZONE: the zone where you want to create the instance.MACHINE_SERIES: the lowercase machine series, such asn4,n4d,n4a,n2, orn2d. For N1, omitMACHINE_SERIES-and start withcustom-.NUMBER_OF_VCPUS: the number of vCPUs.AMOUNT_OF_MEMORY_MB: the total amount of memory in MB. This value must be an integer multiple of 256 MB.
For example, the following specifies an N2 machine type with 2 vCPUs and 20 GB (20,480 MB) of extended memory:
zones/ZONE/machineTypes/n2-custom-2-20480-ext
Add extended memory to an existing VM instance
To add more memory to an existing instance that uses a custom machine type, you must first stop the instance. After the instance stops, complete the following steps to add more memory to the VM:Console
In the Google Cloud console, go to the VM instances page.
Click the name of the stopped VM that you want to modify.
At the top of the page, click Edit.
In the Machine configuration section, verify that Custom is selected under Machine type.
To add extended memory, select Extend Memory, and then specify the amount of Memory that you need.
Click Save.
To restart the VM, at the top of the page, click Start / Resume.
gcloud
Stop the VM by running the
gcloud compute instances stopcommand:gcloud compute instances stop INSTANCE_NAME \ --zone=ZONEUpdate the custom machine type with extended memory by running the
gcloud compute instances set-machine-typecommand with the--custom-cpu,--custom-memory,--custom-vm-type, and--custom-extensionsflags:gcloud compute instances set-machine-type INSTANCE_NAME \ --zone=ZONE \ --custom-cpu=NUMBER_OF_VCPUS \ --custom-memory=AMOUNT_OF_MEMORY \ --custom-vm-type=MACHINE_SERIES \ --custom-extensionsAlternatively, you can pass the full custom machine type string with the
-extsuffix to the--machine-typeflag:gcloud compute instances set-machine-type INSTANCE_NAME \ --zone=ZONE \ --machine-type=MACHINE_SERIES-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB-extReplace the following:
INSTANCE_NAME: the name of the VM.ZONE: the zone where the VM is located.NUMBER_OF_VCPUS: the number of vCPUs.AMOUNT_OF_MEMORY: the total amount of memory with a unit suffix (MBorGB), or in GB if you omit the unit.AMOUNT_OF_MEMORY_MB: the total amount of memory in MB. This value must be an integer multiple of 256 MB.MACHINE_SERIES: the lowercase machine series that supports extended memory, such asn4,n4d,n4a,n2,n2d, orn1. For N1 with the--machine-typeflag, omitMACHINE_SERIES-and start withcustom-.
Restart the VM by running the
gcloud compute instances startcommand:gcloud compute instances start INSTANCE_NAME \ --zone=ZONE
Go
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Java
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 client libraries.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Python
Before 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 client libraries.
REST
- Stop the VM by calling the
instances.stopmethod. Update the machine type resources by calling the
instances.setMachineTypemethod and specifying the-extsuffix in themachineTypefield:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/setMachineType { "machineType": "zones/ZONE/machineTypes/MACHINE_SERIES-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB-ext" }Replace the following:
PROJECT_ID: the ID of the project that contains the VM.ZONE: the zone where the VM is located.INSTANCE_NAME: the name of the VM.MACHINE_SERIES: the lowercase machine series, such asn4,n4d,n4a,n2, orn2d. For N1, omitMACHINE_SERIES-and start withcustom-.NUMBER_OF_VCPUS: the number of vCPUs.AMOUNT_OF_MEMORY_MB: the total amount of memory in MB. This value must be an integer multiple of 256 MB.
Restart the VM by calling the
instances.startmethod.
What's next
- Learn more about machine families.
- After creating a VM, complete a tutorial to start using a VM instance.
- Learn how to connect to your VM instance.