Reputation: 31
We have a VM set up on Google Cloud and are keen to be able to automate or schedule turning it on and off.
We have automated scripts inside that do the work after that and so far what I've read in the literature by google is more in relation to those instances but I haven't been able to find anything that helps us.
I know that other systems like in Azure this is achievable. I.e
Schedule Azure VM to turn on, run a script and turn off
I'm looking for the Google equivalent use case and steps please!
Thanks so much.
Background
Hi Everyone, I have no coding experience. I am asking this question to help out a team mate who has asked me as product dev if I can figure this out while he does important heavy lifting.
We are a small team, trying to save what little we can and use Google VM's to run some scripts that are quite important. Even though the machine being on all the time only would only cost $$/month but we live on peanuts and decided to limit the runtime to once a week and we can really manage a lot at the moment with that.
Would really appreciate any and all help in how we can achieve this because otherwise I need to login regularly and turn it on and off and if forgetting to do so one week could be pretty bad.
Upvotes: 3
Views: 2048
Reputation: 75775
You can use Cloud Scheduler. Here an example of configuration
https://compute.googleapis.com/compute/v1/projects/YOUR_PROJECT_ID/zones/YOUR_COMPUTE_ZONE/instances/YOUR_INSTANCE_NAME/stop
https://compute.googleapis.com/compute/v1/projects/YOUR_PROJECT_ID/zones/YOUR_COMPUTE_ZONE/instances/YOUR_INSTANCE_NAME/start
For both, you need to use POST method. The URL are the same, only the stop and start change at the end. Replace with your project your compute name and zone and that's all
Then set your frequency and timezone.
You have to add the authorization to Cloud Scheduler to start and stop your VM. For this, click on SHOW MORE
and the Auth header and service account fields will appear.
here the easiest is to use the Compute Engine default service account (pattern: [email protected]
. But, and it's better, you can also create a specific service account and grant on it only the required role Compute Instance Admin
Upvotes: 7