Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP auto shutdown and startup using Google Cloud Schedulers

I want to start/stop a set of Compute engine instances in Google Cloud Platform using Google Cloud Scheduler. How can I do it?

like image 245
anXler Avatar asked Nov 13 '19 05:11

anXler


2 Answers

In order to start and stop a Compute Engine using the Cloud Scheduler you can follow Google this tutorial, or this other

I won’t be copy-pasting the required code here because the tutorial it's very complete but I will resume here the steps to follow.

  1. Set up your Compute Engine instances
  2. Deploy the starter Cloud Function. You can see an example in here
  3. Deploy the stop Cloud Function. You can see an example in here
  4. Set up the Cloud Scheduler jobs

If you need any help with the tutorial please just let me know!

like image 109
Chris32 Avatar answered Oct 02 '22 01:10

Chris32


I still wonder why gcp has still not have this feature in the first place. Anyways These simple steps did the job for me

  • Create a new JobScheduler.
  • Fill in the required details
  • Choose frequency which suits your requirement.
  • Choose the target to Pub/Sub.
  • Choose the topic name (Create a new topic if not created ).
  • In the payload section use this stop script gcloud compute instances stop instance-name.

To verify the change you can run the job manually and check

like image 32
Masood Avatar answered Oct 02 '22 00:10

Masood