generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 3
Google Cloud Scheduler
Kadi-7 edited this page Jul 4, 2023
·
3 revisions
Author: Abdelkader Alkadour
Date: 28.06.2023
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.
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.
-
Open the Google Cloud Console and go to VM Instances.
- Click on INSTANCE SCHEDULES.
- Then click on CREATE SCHEDULE.
-
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:
You can use the Crontab Guru website for creating custom CRON expressions.
0 17 * * MON-FRI
- Time zone: Pick the time zone of your country.
- Finally, click on Submit to create the scheduler.
-
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.
- You may see the following error message, which is normal. You will fix it in the next steps.
- Note the service account mentioned. You will need it in the following steps.
-
Creating Role
- Write Roles in the search bar and go to Role in IAM & Admin, then click on CREATE ROLE.
- Choose a title for the role and click on ADD PERMISSIONS.
compute.instances.start
and
compute.instances.stop
in the search bar:
- Make sure to add both permissions as shown in the picture.
- Once you have added the permissions, click on ADD, and then click on CREATE in the create role dialogue box.
-
Assign the Role to the scheduler.
- Navigate to IAM & Admin. Then click on GRANT ACCESS.
-
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.
- Now you can successfully add VMs to the Scheduler, resolving the issue that was encountered in Step 3.