Seleccionar un entorno de ejecución para los servicios
Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
En esta página se describe cómo especificar el entorno de ejecución de las instancias de Cloud Run. De forma predeterminada, los servicios de Cloud Run no tienen especificado un entorno de ejecución, lo que significa que Cloud Run selecciona el entorno de ejecución en función de las funciones utilizadas. Si no especificas un entorno de ejecución para tu servicio, Cloud Run puede seleccionar el entorno de primera o de segunda generación.
Ten en cuenta que los trabajos de Cloud Run solo usan el entorno de ejecución de segunda generación y que no se puede cambiar.
Consulta la documentación sobre el concepto de entornos de ejecución para obtener ayuda a la hora de elegir el entorno que mejor se adapte a tu servicio.
Roles obligatorios
Para obtener los permisos que necesitas para configurar e implementar servicios de Cloud Run, pide a tu administrador que te conceda los siguientes roles de gestión de identidades y accesos:
Si vas a desplegar un servicio o una función a partir de código fuente, también debes tener otros roles concedidos en tu proyecto y en la cuenta de servicio de Cloud Build.
Cualquier cambio en la configuración conlleva la creación de una nueva revisión. Las revisiones posteriores también recibirán automáticamente este ajuste de configuración, a menos que hagas cambios explícitos para modificarlo.
El valor predeterminado de los servicios de Cloud Run es sin especificar, lo que significa que Cloud Run selecciona un entorno de ejecución adecuado.
También puedes especificar un entorno de ejecución. Para usar la segunda generación, debes especificar al menos 512 MiB de memoria.
Puedes definir el entorno de ejecución mediante la Google Cloud consola, la línea de comandos gcloud o un archivo YAML cuando creas un servicio o desplegas una revisión:
Seleccione Servicios en el menú y haga clic en Implementar contenedor para configurar un nuevo servicio.
Si vas a configurar un servicio que ya tienes, haz clic en él y, a continuación, en Editar y desplegar nueva revisión.
Si vas a configurar un servicio nuevo, rellena la página de configuración inicial del servicio y, a continuación, haz clic en Contenedores, volúmenes, redes y seguridad para desplegar la página de configuración del servicio.
Haz clic en la pestaña Contenedor.
Selecciona el entorno de ejecución que quieras con los botones de opción. Mantén la opción "Predeterminado" para que Cloud Run seleccione un entorno de ejecución adecuado.
Sustituye SERVICE por el nombre de tu servicio y ENVIRONMENT por el entorno de ejecución que quieras. Especifica el valor gen1 para la primera generación o gen2 para la segunda.
También puedes definir el entorno de ejecución durante la implementación con el siguiente comando:
IMAGE_URL: una referencia a la imagen del contenedor, por ejemplo, us-docker.pkg.dev/cloudrun/container/hello:latest. Si usas Artifact Registry, el repositorioREPO_NAME ya debe estar creado. La URL sigue el formato LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
.
ENVIRONMENT: el entorno de ejecución que quieras. Especifica el valor gen1 para la primera generación o gen2 para la segunda.
YAML
Si va a crear un servicio, puede saltarse este paso.
Si va a actualizar un servicio, descargue su configuración YAML:
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-21 (UTC)."],[],[],null,["# Select an execution environment for services\n\nThis page describes how to specify the [execution environment](/run/docs/about-execution-environments) of\nCloud Run instances. Cloud Run services by default don't\nhave an execution environment specified, which means Cloud Run selects\nthe execution environment based on the features used. If you don't specify an\nexecution environment for your service, Cloud Run can select either the\nfirst generation or the second generation environment.\n\nNote that Cloud Run jobs only use the second generation\nexecution environment, and this cannot be changed for jobs.\n\nConsult the [execution environments](/run/docs/about-execution-environments) concept\ndocumentation for assistance in choosing the environment that is best for your\nservice.\n\nRequired roles\n--------------\n\n\nTo get the permissions that\nyou need to configure and deploy Cloud Run services,\n\nask your administrator to grant you the\nfollowing IAM roles:\n\n- [Cloud Run Developer](/iam/docs/roles-permissions/run#run.developer) (`roles/run.developer`) on the Cloud Run service\n- [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity\n\n\nIf you are deploying a [service](/run/docs/deploying-source-code#required_roles)\nor [function](/run/docs/deploy-functions#required-roles) from source code, you\nmust also have additional roles granted to you on your project and\nCloud Build service account.\n\nFor a list of IAM roles and permissions that are associated with\nCloud Run, see\n[Cloud Run IAM roles](/run/docs/reference/iam/roles)\nand [Cloud Run IAM permissions](/run/docs/reference/iam/permissions).\nIf your Cloud Run service interfaces with\nGoogle Cloud APIs, such as Cloud Client Libraries, see the\n[service identity configuration guide](/run/docs/configuring/services/service-identity).\nFor more information about granting roles, see\n[deployment permissions](/run/docs/reference/iam/roles#additional-configuration)\nand [manage access](/iam/docs/granting-changing-revoking-access).\n\nSet and update execution environment\n------------------------------------\n\nAny configuration change leads to the\ncreation of a new revision. Subsequent revisions will also automatically get\nthis configuration setting unless you make explicit updates to change it.\n\nThe default for Cloud Run services is *unspecified* , which means\nthat Cloud Run selects a suitable execution environment.\nAlternatively, you can specify an execution environment. To use second generation,\nyou must [specify at least 512 MiB of memory](/run/docs/configuring/services/memory-limits).\n\nYou can set the execution environment using the Google Cloud console, the gcloud\ncommand line, or a YAML file when you [create a new service](/run/docs/deploying#service) or\n[deploy a new revision](/run/docs/deploying#revision): \n\n### Console\n\n\n1. In the Google Cloud console, go to Cloud Run:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Select **Services** from the menu, and click **Deploy container** to\n configure a new service.\n If you are configuring an existing service, click the\n service, then click **Edit and deploy new revision**.\n\n3. If you are configuring a new service, fill out the initial service\n settings page, then click **Container(s), Volumes, Networking, Security** to expand the\n service configuration page.\n\n4. Click the **Container** tab.\n\n - Select the desired execution environment using the option buttons. Keep \"Default\" to let Cloud Run select a suitable execution environment.\n5. Click **Create** or **Deploy**.\n\n### gcloud\n\nYou can [update the execution environment](/sdk/gcloud/reference/run/services/update)\nfor a given service by using the following command:\n\n\u003cbr /\u003e\n\n```bash\ngcloud run services update SERVICE --execution-environment ENVIRONMENT\n```\n\n\u003cbr /\u003e\n\nReplace \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e with the name of your service and \u003cvar translate=\"no\"\u003eENVIRONMENT\u003c/var\u003e\nwith the desired execution environment. Specify the value `gen1` for first\ngeneration or `gen2` for second generation.\n\nYou can also set the execution environment during\n[deployment](/sdk/gcloud/reference/run/deploy) using the command:\n\n\u003cbr /\u003e\n\n```bash\ngcloud run deploy --image IMAGE_URL --execution-environment ENVIRONMENT\n```\n\n\u003cbr /\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e: a reference to the container image, for example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry, the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e .\n- \u003cvar translate=\"no\"\u003eENVIRONMENT\u003c/var\u003e: the desired execution environment. Specify the value `gen1` for first generation or `gen2` for second generation.\n\n### YAML\n\n1. If you are creating a new service, skip this step.\n If you are updating an existing service, download its [YAML configuration](/run/docs/reference/yaml/v1):\n\n ```bash\n gcloud run services describe SERVICE --format export \u003e service.yaml\n ```\n2. set the `run.googleapis.com/execution-environment` annotation:\n\n ```yaml\n apiVersion: serving.knative.dev/v1\n kind: Service\n metadata:\n name: SERVICE\n spec:\n template:\n metadata:\n annotations:\n run.googleapis.com/execution-environment: ENVIRONMENT\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSERVICE\u003c/var\u003e: the name of your Cloud Run service.\n - \u003cvar translate=\"no\"\u003eENVIRONMENT\u003c/var\u003e: the selected execution environment. Specify the value `gen1` for first generation or `gen2` for second generation.\n\n Remove the `run.googleapis.com/execution-environment` annotation for the\n default behavior.\n3. Create or update the service using the following command:\n\n ```bash\n gcloud run services replace service.yaml\n ```\n\n### Terraform\n\n\u003cbr /\u003e\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\nAdd the following to a [`google_cloud_run_v2_service`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service) resource in your Terraform configuration: \n\n\u003cbr /\u003e\n\n resource \"google_cloud_run_v2_service\" \"default\" {\n name = \"cloudrun-service-execution-environment\"\n location = \"\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\"\n\n template {\n containers {\n image = \"us-docker.pkg.dev/cloudrun/container/hello\"\n }\n execution_environment = \"\u003cvar translate=\"no\"\u003eENVIRONMENT\u003c/var\u003e\"\n }\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the Google Cloud region. For example, `europe-west1`.\n- \u003cvar translate=\"no\"\u003eENVIRONMENT\u003c/var\u003e: `EXECUTION_ENVIRONMENT_GEN1` for first generation, or `EXECUTION_ENVIRONMENT_GEN2` for second generation.\n\nView Execution environment settings\n-----------------------------------\n\nTo view the current Execution environment settings for your\nCloud Run service: \n\n### Console\n\n1. In the Google Cloud console, go to Cloud Run:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Click the service you are interested in to open the **Service details**\n page.\n\n3. Click the **Revisions** tab.\n\n4. In the details panel at the right, the Execution environment setting\n is listed under the **Container** tab.\n\n### gcloud\n\n1. Use the following command:\n\n ```bash\n gcloud run services describe SERVICE\n ```\n2. Locate the Execution environment setting in the returned\n configuration."]]