A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/compute/docs/instances/limit-vm-runtime below:

Limit the run time of a VM | Compute Engine Documentation

Skip to main content Limit the run time of a VM

Stay organized with collections Save and categorize content based on your preferences.

This document explains how to limit the run time of new or existing virtual machine (VM) instances and how to monitor the run time of those VMs. For managed instance groups (MIGs), see Limit the run time of a MIG instead.

When limiting the run time of a VM, you can schedule the VM to be automatically terminated (stopped or deleted) when it reaches a specific time limit (duration or time). Use time limits to help optimize temporary workloads—by automatically limiting VM run times, you can help minimize costs and free up quotas.

Note: GPU VMs that are configured to be automatically deleted after a predefined run time of 7 days or less can consume either preemptible or standard allocation quotas. This behavior is intended to help you improve the obtainability of allocation quota for temporary-but-uninterrupted workloads. For more information about this behavior, see GPU VMs and preemptible allocation quotas.

To learn how to immediately stop a VM, see Stop or restart a VM. To learn how to immediately delete a VM, see Delete a VM.

Before you begin Restrictions

Limiting the run time of a VM has the following restrictions:

Limit the run time of a new VM

The following sections describe how to configure a time limit while creating a new VM. You can specify the time limit, which is when you want a VM to automatically terminate, as either a duration (maxRunDuration) or a time (terminationTime).

When deciding the type of time limit for a VM, consider that the VM might be interrupted—for example, by a user request or by a host event. The behavior of a time limit varies based on the type of interruption and the type of time limit:

Set a duration

A duration represents the total run time that you want for a VM. To create a VM that is automatically terminated after the VM runs for a specific duration, use the Google Cloud console, Google Cloud CLI, Terraform, or Compute Engine API.

Console
  1. In the Google Cloud console, go to the Create an instance page.

    Go to Create an instance

  2. In the Availability policies section, expand VM provisioning model advanced settings.

  3. Select the Set a time limit for the VM checkbox. The Time limit type field appears.

  4. In the Time limit type field, select By hours (default) to specify the time limit as a duration. In the following field, enter the duration in hours.

  5. In the On VM termination list, select what happens when the run time of the VM reaches the specified time limit:

  6. Optional: Specify other VM options. For more information, see Creating and starting a VM instance.

  7. To create and start the VM, click Create.

gcloud

To create a VM from the gcloud CLI, use the gcloud compute instances create command.

gcloud compute instances create VM_NAME \
    --max-run-duration=DURATION \
    --instance-termination-action=TERMINATION_ACTION

Replace the following:

For more information about other options you can specify when creating a VM, see Creating and starting a VM instance.

Terraform

To create a VM using Terraform, use the google_compute_instance resource.

For more information, see the Terraform documentation for the google_compute_instance resource.

REST

To create a VM from the Compute Engine API, use the instances.insert method. You must specify a name, machine type, and boot disk for the VM.

To create a VM that is automatically terminated after a specific duration, you must include the maxRunDuration field. To specify the termination action, include the instanceTerminationAction field, which is optional for Spot VMs.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
  "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
  "name": "VM_NAME",
  "disks": [
    {
      "initializeParams": {
        "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
      },
      "boot": true
    }
  ]
  "scheduling":
  {
    "maxRunDuration":
    {
      "seconds": DURATION
    },
    "instanceTerminationAction": "TERMINATION_ACTION"
  },
}

Replace the following:

For more information about the options you can specify when creating a VM, see Creating and starting a VM instance.

Set a time

A time represents the date, time, and timezone when you want a VM to be terminated. To create a VM that is automatically terminated at a specific time, use the Google Cloud console, Google Cloud CLI, or Compute Engine API.

Console
  1. In the Google Cloud console, go to the Create an instance page.

    Go to Create an instance

  2. In the Availability policies section, expand VM provisioning model advanced settings.

  3. Select the Set a time limit for the VM checkbox. The Time limit type field appears.

  4. In the Time limit type field, select By date to specify the time limit as a time and date. In the following field, click date_range Select date and time and select the date, time, and timezone for the time limit.

  5. In the On VM termination list, select what happens when the run time of the VM reaches the specified time limit:

  6. Optional: Specify other VM options. For more information, see Creating and starting a VM instance.

  7. To create and start the VM, click Create.

gcloud

To create a VM from the gcloud CLI, use the gcloud compute instances create command.

gcloud compute instances create VM_NAME \
    --termination-time=TIME \
    --instance-termination-action=TERMINATION_ACTION

Replace the following:

For more information about other options you can specify when creating a VM, see Creating and starting a VM instance.

REST

To create a VM from the Compute Engine API, use the instances.insert method. You must specify a name, machine type, and boot disk for the VM.

To create a VM that is automatically terminated at a specific time, you must include the terminationTime field. To specify the termination action, include the instanceTerminationAction field, which is optional for Spot VMs.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
  "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
  "name": "VM_NAME",
  "disks": [
    {
      "initializeParams": {
        "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
      },
      "boot": true
    }
  ]
  "scheduling":
  {
    "terminationTime": "TIME",
    "instanceTerminationAction": "TERMINATION_ACTION"
  },
}

Replace the following:

For more information about the options you can specify when creating a VM, see Creating and starting a VM instance.

Limit the run time of an existing VM

You can limit the run time of an existing VM by updating the VM's schedule. If you don't already understand how to configure settings for time limits, review the previous sections about how to limit the run time of a new VM first.

You can use the Google Cloud console, Google Cloud CLI, or Compute Engine API to update the VM's scheduling-related properties, as described in this section. This method requires that you first stop your VM, then update its properties, then restart it. Alternatively, if you want to simultaneously update additional VM properties and automatically stop and restart a VM, see Update instance properties instead.

Console
  1. In the Google Cloud console, go to the VM instances page.

    Go to VM instances

  2. In the Name column, click the name of the VM that you want to update.

  3. From the VM instance details page, complete the following steps:

    1. If the VM is running, click Stop to stop the VM.
    2. To edit the VM, click edit Edit.
    3. On the Edit instance page, complete the following steps:

      1. In the Availability policies section, modify the Set a time limit for the VM checkbox and any fields below it as desired.

        For more information about how to configure the properties for time limits, see limit the run time of a new VM.

      2. To save your changes, click Save.

    4. Optional: If you want to start running the VM now, click Start.

gcloud

To update a VM's time limit by using the gcloud CLI, complete the following steps:

  1. If the VM is running, stop the VM by using the gcloud compute instances stop command:

    gcloud compute instances stop VM_NAME
    

    Replace VM_NAME with the name of VM that you want to update.

  2. Update the VM's time limit by using the gcloud compute instances set-scheduling command.

    gcloud compute instances set-scheduling VM_NAME \
        --max-run-duration=DURATION \
        --termination-time=TIME \
        --instance-termination-action=TERMINATION_ACTION \
        --discard-local-ssds-at-termination-timestamp=true
    

    Configure the following flags:

    Then, replace the following:

  3. If you want the VM to start running, start the VM by using the gcloud compute instances start command:

    gcloud compute instances start VM_NAME
    

    Replace VM_NAME with the name of the VM.

REST

To update a VM's time limit by using the Compute Engine API, complete the following steps:

  1. If the VM is running, stop the VM by using the instances.stop method:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop
    

    Replace the following:

  2. Update the VM's scheduling property, including fields for the VM's time limit, by using the instances.setScheduling method. Include either the maxRunDuration field or the terminationTime field to set the time limit as either a duration or time, respectively:

    Replace the following:

  3. If you want the VM to start running, start the VM by using the instances.start method:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/start
    

    Replace the following:

Monitor the run time of a VM

You can monitor the run time of a VM that has a time limit by using the following options:

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This document details how to set time limits for virtual machine (VM) instances, enabling automatic termination (stop or delete) after a specified duration or at a set time."],["Setting time limits on VMs helps manage temporary workloads, minimize costs, and free up quotas by automatically terminating them upon reaching the defined limit."],["You can configure a new or existing VM to be automatically terminated either by specifying a maximum run duration (from 30 seconds to 120 days) or by setting a specific termination time, with the ability to choose whether the VM should be stopped or deleted."],["When setting a duration for a time limit, the termination timestamp is calculated by adding the duration to the VM's start time, whereas setting a specific time defines the exact termination point, but the specified time must always be in the future."],["To monitor VM run time, you can view the VM's `terminationTimestamp` field to see when it's scheduled for termination, or check the VM operations for `compute.instances.deferredStop` or `compute.instances.deferredDelete` to verify if the VM was automatically stopped or deleted due to a time limit."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4