Selecting an execution environment

This page describes how to specify the execution environment for each Cloud Run container instance. By default Cloud Run container instances run in the first generation execution environment. You can change this if you want. Consult the Execution environments concept documentation for assistance in choosing the environment that is best for your service.

Setting and updating execution environment

Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.

By default, each container instance uses the first generation execution environment. If you use second generation, you must also specify at least 512 MiB of memory.

You can set execution environment using the Cloud Console, the gcloud command line, or a YAML file when you create a new service or deploy a new revision:

Console

  1. Go to Cloud Run

  2. Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.

  3. If you are configuring a new service, fill out the initial service settings page as desired, then click Next > Advanced settings to reach the service configuration page.

  4. Click the Container tab.

    image

  5. Select the desired execution environment using the option buttons.

  6. Click Create or Deploy.

Command line

You can update the execution environment for a given service by using the following command:

gcloud beta run services update SERVICE --execution-environment ENVIRONMENT

Replace SERVICE with the name of your service and ENVIRONMENT with the desired execution environment. Specify the value gen1 for first generation or gen2 for second generation.

You can also set the execution environment during deployment using the command:

gcloud beta run deploy --image IMAGE_URL --execution-environment ENVIRONMENT

Replace

  • IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest.
  • ENVIRONMENT with the desired execution environment. Specify the value gen1 for first generation or gen2 for second generation.

YAML

You can download and view existing service configuration using the gcloud run services describe --format export command, which yields cleaned results in YAML format. You can then modify the fields described below and upload the modified YAML using the gcloud run services replace command. Make sure you only modify fields as documented.

  1. To view and download the configuration:

    gcloud run services describe SERVICE --format export > service.yaml
  2. set the run.googleapis.com/execution-environments annotation:

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: SERVICE
    spec:
      template:
        metadata:
          annotations:
            run.googleapis.com/execution-environment: ENVIRONMENT

    Replace

    • SERVICE with the name of your Cloud Run service
    • ENVIRONMENT with the desired execution environment. Specify the value gen1 for first generation or gen2 for second generation.
  3. Replace the service with its new configuration using the following command:

    gcloud run services replace service.yaml

Viewing Execution environment settings

To view the current Execution environment settings for your service:

Console

  1. Go to Cloud Run

  2. Click the service you are interested in to open the Service details page.

  3. Click the Revisions tab.

  4. In the details panel at the right, the Execution environment setting is listed under the Container tab.

Command line

  1. Use the following command:

    gcloud run services describe SERVICE
  2. Locate the Execution environment setting in the returned configuration.