By Vishal Bulbule．Jan 2, 2023
In this article, we will see how we can schedule GCE Instance (VM) restart using Instance Schedule managed featured in GCP. We will also see all limitations with this feature.
To use instance schedules, the compute service agent ( not service account) for your project must have the following permissions:
compute.instances.startto schedule VM instances to start.
compute.instances.stopto schedule VM instances to stop.
The above permissions are available in Compute Instance Admin V1 role so you can assign this role.
- Go to compute Engine page.
- Click the Instance schedules tab at the top of the page
- Click Create schedule. The Create a schedule pane opens.
- Enter a Name.
- Optional: Enter a Description.
- In the Region drop-down menu, select the location for this instance schedule.
- Define when the instance schedule starts and stops any attached VM instances. If you need VM instances to start or stop at a specific time, schedule the operation 15 minutes earlier than needed. Make sure each start and stop operation are at least 15 minutes apart.
- Enter a Start time, a Stop time, or both in 24 hr format or use cron expression.
- Optional: In the Initiate date field, type or click date_range to select the date and time when you want this instance schedule to begin. If omitted, the schedule is effective immediately.
- Optional: In the End date field, type or click date_range to select the date and time when you want this instance schedule to end. If omitted, the schedule is effective indefinitely.
- Click Submit.
- Click on the name of the instance schedule that you want to attach. The Instance schedule details page opens.
- Click Add instances to schedule. The Add instances to schedule pane opens.
- Select the checkbox for each VM instance that you want to attach this schedule to Instance.
- Click Add.
- You can only attach an instance schedule to VM instances that are located in the same region as the instance schedule.
- Each VM instance can only follow one instance schedule, but you can attach each instance schedule to up to 1,000 VM instances.
- Instance schedules do not provide capacity guarantees, so if the resources required for a scheduled VM instance are not available at the scheduled time, your VM instance might not start when scheduled. Although you can reserve VM instances before starting them to provide capacity guarantees, reservations cannot be automatically scheduled.
- Instance schedules only start and stop VM instances at the specified times, but you can manually start and stop VM instances at any time. For example, suppose you have a schedule that starts daily at 8 AM and stops daily at 5 PM. If you attach that schedule to a stopped VM instance at 4 PM, that VM instance does not start until 8 AM the next day unless you manually start the VM instance before then.
- Scheduled VM instances might take up to 15 minutes past the scheduled time to begin a start or stop operation. If you need VM instances to start or stop at a specific time, schedule the operation 15 minutes earlier than needed, and schedule each operation at least 15 minutes apart.
- Each instance schedule lets you have up to one start operation and up to one stop operation per hour.
- You cannot edit instance schedules. To change an existing instance schedule for one or more VM instances, remove and delete the existing instance schedule, then create and attach a new instance schedule.
There are multiple scenarios and solutions available based on requirements. Please find my article and below playlist on Managing GCP VM restart.
Please refer below videos for a demo and alternate solutions
The original article published on Medium.