GCP Free Learning
,

What is a preemptible VM?

by

GCP Free Learning

A preemptible VM in Google Cloud Platform (GCP) is an instance that can be terminated by Google with a 30-second notice if the system requires resources. These instances are more cost-effective than regular instances, but they are not suitable for long-running or critical workloads, as they have a maximum runtime of 24 hours.

Here’s a detailed explanation of how to create a preemptible Compute Engine instance in GCP using the 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” button to start creating a new instance.

d. Fill in the required fields such as instance name, region, zone, and machine type.

e. Choose a boot disk by clicking on the “Change” button under the “Boot disk” section. Select the desired OS image and disk size.

f. Expand the “Management, security, disks, networking, sole tenancy” section.

g. In the “Management” tab, under “Availability policy,” check the “Preemptibility” checkbox.

h. Configure additional settings like network, external IP, and firewall rules, as required.

i. Click the “Create” button to launch the preemptible instance.

2. Using gcloud CLI:

First, make sure you have the Google Cloud SDK (https://cloud.google.com/sdk/docs/install) installed.

a. Open the terminal (Command Prompt or PowerShell on Windows, Terminal on macOS or Linux).

b. Authenticate with your Google Cloud account using the following command:

gcloud auth login

c. Set your GCP project:

gcloud config set project PROJECT_ID

d. Launch a new preemptible instance with the desired configuration:

gcloud compute instances create INSTANCE_NAME \
    --image-family IMAGE_FAMILY \
    --image-project IMAGE_PROJECT \
    --machine-type MACHINE_TYPE \
    --boot-disk-size DISK_SIZE_GB \
    --zone ZONE \
    --preemptible

Replace INSTANCE_NAME, IMAGE_FAMILY, IMAGE_PROJECT, MACHINE_TYPE, DISK_SIZE_GB, and ZONE with appropriate values.

3. Using Terraform:

First, make sure you have Terraform installed (https://learn.hashicorp.com/tutorials/terraform/install-cli).

a. Create a new directory for your Terraform configuration:

mkdir gcp-instance
cd gcp-instance

b. Create a main.tf file with the following content:

provider "google" {
  credentials = file("<PATH_TO_YOUR_SERVICE_ACCOUNT_JSON>")
  project     = "<YOUR_PROJECT_ID>"
  region      = "us-central1"
}

resource "google_compute_instance" "preemptible" {
  name         = "preemptible-instance"
  machine_type = "n1-standard-1"
  zone         = "us-central1-a"

  scheduling {
    preemptible = true
    automatic_restart = false
  }

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    network = "default"
    access_config {
      // Ephemeral external IP
    }
  }
}

Replace <PATH_TO_YOUR_SERVICE_ACCOUNT_JSON> and <YOUR_PROJECT_ID> with appropriate values.

c. Initialize Terraform:

terraform init

d. Review the execution plan:

terraform plan

e. Apply the changes to create the preemptible instance:

terraform apply

After creating the preemptible VM, you can use it similarly to a regular instance

Glance and Google’s Next-Level Gaming Recommendation Engine

Collaborative Excellence: Glance and Google’s Next-Level Gaming Recommendation Engine Introduction: In the dynamic gaming industry, personalized recommendations are crucial for..

gcp_ml gcp_ml

Digits and Google Cloud ML

How Digits is Transforming the Accounting Landscape Using Google Cloud ML The finance and accounting industry is experiencing a significant..

GCP AI GCP AI

Google Cloud’s Vertex AI Model Garden and the Launch of Generative AI Studio

Google Cloud’s Vertex AI Model Garden and the Launch of Generative AI Studio Artificial Intelligence (AI) and Machine Learning (ML)..

GCP AI/ML GCP AI/ML

Google Cloud’s Pioneering AI Models and the Launch of Generative AI Studio

 Google Cloud’s Pioneering AI Models and the Launch of Generative AI Studio Artificial Intelligence (AI) continues to break new grounds,..

GCP App Engine GCP App Engine

How to scale an App Engine application in GCP?

Scaling an App Engine application involves configuring the scaling settings in the app.yaml file and deploying the changes. I’ll provide..

Leave a Reply

Your email address will not be published. Required fields are marked *