Skip to content

Google Cloud Scheduler

Kadi-7 edited this page Jul 4, 2023 · 3 revisions

Author: Abdelkader Alkadour

Date: 28.06.2023

Setting up and Configuring Google Cloud Scheduler for Automatic VM Management

This documentation provides instructions for setting up and configuring the Google Cloud Scheduler to automatically run and stop the VMs. Please follow the steps below to ensure a successful setup.

Prerequisites

Before you begin, please ensure that you have the following:

  • VMs: Make sure the VMs you want to automate are already created in your Google Cloud Platform (GCP) project.
  • VM Region: Ensure that all the VMs are located in the same region.

Configuration Steps

  1. Open the Google Cloud Console and go to VM Instances.

    • Click on INSTANCE SCHEDULES.
    image
    • Then click on CREATE SCHEDULE.
    image

  1. Create the Scheduler.

    • In the dialogue window, click on Use CRON expression.
    • Fill in the following details:
      • Name: Provide a name for the scheduler.
      • Region: Set the region to the region where the VMs are created.
      • Start CRON expression: Use the following CRON expression for starting the VMs each workday from Monday to Friday, from 09:00 to 17:00:
        0 9 * * MON-FRI
        
      • Stop CRON expression: Use the following CRON expression for stopping the VMs each workday from Monday to Friday, from 17:00 to 09:00 of the next day:
        0 17 * * MON-FRI
        
        You can use the Crontab Guru website for creating custom CRON expressions.
      • Time zone: Pick the time zone of your country.
    image
    • Finally, click on Submit to create the scheduler.

  1. Add VMs to the scheduler

    • After the scheduler is created, click on the name of the Scheduler, and then click on ADD INSTANCES TO THE SCHEDULER.
    image
    • You may see the following error message, which is normal. You will fix it in the next steps.
    image
    • Note the service account mentioned. You will need it in the following steps.

  1. Creating Role

    • Write Roles in the search bar and go to Role in IAM & Admin, then click on CREATE ROLE.
    image
    • Choose a title for the role and click on ADD PERMISSIONS.
    image
     compute.instances.start

    and

    compute.instances.stop

    in the search bar:
    image

    • Make sure to add both permissions as shown in the picture.
    image
    • Once you have added the permissions, click on ADD, and then click on CREATE in the create role dialogue box.

  1. Assign the Role to the scheduler.

    • Navigate to IAM & Admin. Then click on GRANT ACCESS.
    image
    • On the "New principle" section, choose the name of the service account you noted at the end of Step 3.

    • On "Assign Role," choose Custom and enter the name of the role you created at the end of Step 4.

    image
    • Now you can successfully add VMs to the Scheduler, resolving the issue that was encountered in Step 3.
Clone this wiki locally