Search code examples
google-compute-enginegoogle-compute-api

Is there a way to restart pre-emptible Google Cloud VM instances (Compute Engine) on an hourly basis if it has stopped?


I have some science jobs to run where the instance is has a mounted network drive to a server that is always. Since the cost of always on VMs cost double, I wanted to run pre-emptible VMs but restart them hourly if they have stopped. I want the jobs to finish, but I also don't want to blow the budget on always on instances when I can have a little down time pay half the hourly rate.


Solution

  • Per this document, Compute Engine always terminates preemptible instances after they run for 24 hours. If you start or shut down the instance via the click “start” or “stop” button in the Google Cloud Console instance page, these actions will reset the 24-hour counter for preemptible instances.

    If your science jobs always run longer than 24 hours, and you want to avoid jobs being interrupted, or if you want restart your preemptible instance hourly, you can use Cloud scheduler to start or stop your instance at a fixed time.