0
0
GcpConceptBeginner · 3 min read

Preemptible VM in GCP: What It Is and When to Use It

A preemptible VM in Google Cloud Platform (GCP) is a short-lived, low-cost virtual machine that can be stopped by Google at any time after running for up to 24 hours. It is ideal for batch jobs or fault-tolerant workloads that can handle interruptions.
⚙️

How It Works

Think of a preemptible VM like a rental car that you can use cheaply but must return when the owner needs it back. Google offers these VMs at a lower price because they can stop them anytime, usually when they need resources for other customers.

These VMs run just like regular virtual machines but have a maximum lifetime of 24 hours. If Google needs the resources, it will send a short warning before stopping the VM. This means your work might be interrupted, so preemptible VMs are best for tasks that can pause and resume or restart without problems.

💻

Example

This example shows how to create a preemptible VM using the gcloud command-line tool.

bash
gcloud compute instances create example-preemptible-vm \
  --zone=us-central1-a \
  --machine-type=e2-medium \
  --preemptible \
  --image-family=debian-11 \
  --image-project=debian-cloud
Output
Created [https://www.googleapis.com/compute/v1/projects/your-project/zones/us-central1-a/instances/example-preemptible-vm].
🎯

When to Use

Preemptible VMs are great when you want to save money and your work can handle interruptions. For example:

  • Running batch processing jobs like data analysis or video rendering.
  • Performing large-scale simulations that can restart if stopped.
  • Testing or development environments where uptime is not critical.

They are not suitable for critical applications that need to run continuously without interruption.

Key Points

  • Preemptible VMs cost less but can be stopped anytime within 24 hours.
  • They receive a short warning before shutdown.
  • Best for fault-tolerant and batch workloads.
  • Cannot be used for long-running or critical services.

Key Takeaways

Preemptible VMs offer low-cost compute but can be stopped anytime within 24 hours.
They are ideal for batch jobs and workloads that tolerate interruptions.
Google sends a short warning before stopping the VM.
Not suitable for critical or long-running applications.
Use the --preemptible flag when creating VMs to enable this feature.