Datadog Gold Partner logo

Schedule VM restart using Instance Schedule in GCP

By Vishal Bulbule.Jan 2, 2023

Article-Schedule VM restart using Instance Schedule in GCP-1
Introduction

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.

Permissions Required

To use instance schedules, the compute service agent ( not service account) for your project must have the following permissions:

  • compute.instances.start to schedule VM instances to start.
  • compute.instances.stop to schedule VM instances to stop.

The above permissions are available in Compute Instance Admin V1 role so you can assign this role.

Steps
  1. Go to compute Engine page.
  2. Click the Instance schedules tab at the top of the page
  3. Click Create schedule. The Create a schedule pane opens.
  4. Enter a Name.
  5. Optional: Enter a Description.
  6. In the Region drop-down menu, select the location for this instance schedule.
  7. 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.
  8. Enter a Start time, a Stop time, or both in 24 hr format or use cron expression.
  9. 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.
  10. 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.
  11. Click Submit.
  12. Click on the name of the instance schedule that you want to attach. The Instance schedule details page opens.
  13. Click Add instances to schedule. The Add instances to schedule pane opens.
  14. Select the checkbox for each VM instance that you want to attach this schedule to Instance.
  15. Click Add.
Limitations
  • 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.

Related Posts