How to use Money Saver VM on GCP (Google Cloud Platform)

This section describes how to use Money Saver VM in a Google Compute environment to save upto 80% on VM cost.

What is Preemptible VM?

A Preemptible VM (PVM) is a Google Compute Engine (GCE) virtual machine (VM) instance that can be purchased for a steep discount as long as the customer accepts that the instance will terminate after 24 hours.

How to save using Money Saver VM?

Save upto 80% on VM cost by running this VM. Use Preemptible VMs for your computing needs and this VM will autostart your Preemptible VMs if they are shutdown by GCP thus saving you upto 80% .

Follow below steps to use Money Saver VM with your GCP preemptible vms:

For Home Project: (Money Saver VM is in this project with other vms)

  • The VM will run a script every two minutes to restart stopped preemptible vms only and not regular vms.
  • By default it will start all preemptible vms in the project where it is running.
  • To skip any vm to restart, set a key autostart with a value no in that respective vms metadata.
  • /img/gcp/money-saver-autostart-no.png

    Other Projects: (Money Saver VM is not in this project)

  • 1. To start preemptible vms from other projects, set metadata keys in the money-saver vm as below:
  • a. for first project , key=project1 , value=first project id.
  • b. for second project, key=project2 and value= second project id and so on .
  • /img/gcp/money-saver-metadata.png

  • 2. Add the service key of Money Saver project in other projects.To add the service key follow below steps:
  • a. Run the gcloud auth list command in money saver vm.It will give a service key.
  • /img/gcp/money-saver-service-key.png

  • b. Copy this service key,Go to other project,click on IAM then choose ADD , paste the service key in New Member and select compute engine admin V1 as role and Save.
  • /img/gcp/money-saver-IAM-role.png

  • Now preemptible vms of other projects will autostart with the Money Saver VM
  • Just like for the home project, to skip any preemptible vm from auto start from other project, set a key autostart with a value no in that respective vms metadata.
  • watch money saver vm log using tail command tail -f /var/log/money-saver-vm.log for monitoring.