Google Cloud Instance Scheduling Made Easier

You have a bastion host server which need to run only in office hour(9:00–18:00). There is a compute instance which runs ETL job only on weekend. In the cases like this, keeping the instance turned ON 24 hours will be waste of money and resource. By turning the instance in running state only at the required time will save a lot irrespective of the type of instance. We already know a feature of cloud: on-demand. We can activate the resource on our will at our timing and keep it in terminated state otherwise.

Gone were days where we used to play with Google Cloud SDK, write a cloud function to interact with the compute engine API, create a schedule to run the cloud function and keep track of that also.

Instance Scheduler

But now the instance scheduling is made a lot more easier with few clicks and completely cloud managed. We need to create schedule mentioning the time, start date if any along with the region where the instances are created. Head over to VM Instances and INSTANCE SCHEDULE tab and create one.

Create GCP Instance Schedule

Now, we can add instance to the schedule which are on same region where the schedule is created.

Add Instance to Schedule

On first attempt, it will show access error like this:

This means the schedule will run as the mentioned service account and we have to add the instance start-stop privilege from cloud IAM. On the IAM page, don’t forget to tick Include Google-provided role grants to see the system IAM service account. The account should be under Compute Engine Service Agent. And add the permission to the service account. If the role is not created, have one like below:

Instance Scheduler Role

After adding the IAM permissions, go back to the scheduler page and it should allow you to attach required instance to a schedule.

--

--

DevOps | SRE | #GDE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store