Creating a custom machine type in Compute Engine allows you to tailor the number of vCPUs and memory to fit your specific use case. Here’s how to create a custom machine type using GCP Console, gcloud CLI, and Terraform:
1. Using GCP Console:
a. Go to the GCP Console: https://console.cloud.google.com/
b. Navigate to Compute Engine > VM instances.
c. Click on the “Create instance” button.
d. Fill in the required fields, and under “Machine type”, click on the “Customize” button.
e. Adjust the number of vCPUs and the amount of memory as needed. Note the custom machine type format: custom-CPUS-MEMORY
, where CPUS
is the number of vCPUs and MEMORY
is the memory in MiB.
f. Finish configuring the instance and click the “Create” button.
2. Using gcloud CLI:
a. Run the following command to create a VM instance with a custom machine type:
gcloud compute instances create INSTANCE_NAME \
--machine-type custom-CPUS-MEMORY \
--image-family IMAGE_FAMILY \
--image-project IMAGE_PROJECT \
--boot-disk-size BOOT_DISK_SIZE \
--zone ZONE
Replace INSTANCE_NAME
, CPUS
, MEMORY
, IMAGE_FAMILY
, IMAGE_PROJECT
, BOOT_DISK_SIZE
, and ZONE
with appropriate values.
3. Using Terraform:
a. Create a main.tf
file with the following resource block:
resource "google_compute_instance" "example" {
name = "example-instance"
machine_type = "custom-CPUS-MEMORY"
zone = "ZONE"
boot_disk {
initialize_params {
image = "projects/IMAGE_PROJECT/global/images/family/IMAGE_FAMILY"
size = BOOT_DISK_SIZE
}
}
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
}
}
Replace CPUS
, MEMORY
, ZONE
, IMAGE_FAMILY
, IMAGE_PROJECT
, and BOOT_DISK_SIZE
with appropriate values.
b. Run the following commands to apply the changes:
terraform init
terraform plan
terraform apply
This will create a new Compute Engine instance with a custom machine type tailored to your requirements.
Leave a Reply