Usa el entorno flexible de App Engine en una red de VPC compartida
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En el entorno flexible de App Engine, puedes especificar una red para implementar las instancias de tu servicio. En esta página, se muestra cómo configurar un proyecto para utilizar el entorno flexible de App Engine en una red de VPC compartida.
Si usas Google Cloud CLI, actualiza a la versión más reciente antes de seguir este instructivo. Para ello, ejecuta el siguiente comando:
gcloud components update
Permite el tráfico hacia la red de VPC compartida
Un administrador de una VPC compartida necesita crear una regla de firewall en el proyecto host de la VPC compartida para permitir el tráfico hacia el entorno flexible de App Engine en la red de VPC compartida. La regla de firewall permite la entrega y la verificación de estado del tráfico para las instancias de entorno flexible.
La regla de firewall debe tener las siguientes propiedades:
Red: nombre de la red de VPC compartida
Dirección del tráfico: entrada
Acción si hay coincidencia: permitir
Objetivos: etiquetas de destino especificadas
Etiquetas de destino: aef-instance
Filtro de fuente: rangos de IP
Rangos de IP de origen: 35.191.0.0/16, 130.211.0.0/22
Protocolos y puertos: protocolos y puertos especificados
TCP: 8443, 10402
Un administrador de VPC compartida puede crear la regla de firewall mediante la consola de Google Cloud o Google Cloud CLI:
Console
Para crear la regla de firewall con la Google Cloud consola, haz lo siguiente:
NETWORK_NAME es el nombre de la red de VPC compartida.
HOST_PROJECT_ID es el Google Cloud ID del proyecto
del proyecto host de la VPC compartida.
Configura los permisos
Un administrador de una VPC compartida debe otorgar a las siguientes dos cuentas de servicio la función Usuario de la red de Compute para permitir que un proyecto de servicio implemente instancias en el entorno flexible de App Engine en el red:
Agente de servicio de las API de Google (PROJECT_NUM@cloudservices.gserviceaccount.com)
Agente de servicio del entorno flexible de App Engine (service-PROJECT_NUM@gae-api-prod.google.com.iam.gserviceaccount.com)
Console
Para configurar permisos con la consola de Google Cloud , haz lo siguiente:
Dirígete a la página Configuración de IAM para el proyecto de servicio y toma nota del número de proyecto.
En el campo Nuevos miembros, ingresa las siguientes direcciones de correo electrónico separadas por una coma. Reemplaza PROJECT_NUM por el número de proyecto que obtuviste en el paso 1.
En el menú desplegable Selecciona una función, selecciona Compute Engine > Usuario de la red de Compute.
Haz clic en Guardar.
gcloud
Obtén el número del proyecto de servicio en el que se implementa la app de App Engine. Ejecuta el siguiente comando, pero reemplaza SERVICE_PROJECT_ID por el ID del proyecto de servicio:
Una vez que hayas configurado la regla de firewall y los permisos adecuados, puedes implementar un servicio nuevo o un servicio existente del entorno flexible de App Engine en la red de VPC compartida.
En el archivo app.yaml, usa el campo name de la configuración de red para especificar el nombre completamente calificado de la red de VPC compartida:
Para verificar que tu servicio de entorno flexible de App Engine se ejecute en la red de VPC compartida, consulta la configuración de la versión en la página Versiones de App Engine en la consola deGoogle Cloud :
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThe App Engine flexible environment can be deployed on a Shared VPC network by configuring the host project and service project appropriately.\u003c/p\u003e\n"],["\u003cp\u003eA Shared VPC Admin must create a firewall rule in the Shared VPC host project to allow ingress traffic on specific IP ranges and ports to the App Engine flexible environment, which should be tagged with \u003ccode\u003eaef-instance\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTwo service accounts, the Google APIs service agent and the App Engine flexible environment service agent, must be granted the Compute Network User role in the Shared VPC host project by a Shared VPC Admin.\u003c/p\u003e\n"],["\u003cp\u003eTo deploy an App Engine flexible environment service to a Shared VPC network, the \u003ccode\u003eapp.yaml\u003c/code\u003e file must be configured with the fully-qualified name of the Shared VPC network and optionally a subnetwork name.\u003c/p\u003e\n"],["\u003cp\u003eAfter deployment, the network configuration can be verified on the App Engine versions page in the Google Cloud Console by checking the config column for the desired version.\u003c/p\u003e\n"]]],[],null,["# Using the App Engine flexible environment on a Shared VPC network\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nIn the App Engine flexible environment, you can specify a network\nto deploy your service's instances on. This page shows you how to configure\nyour project to use the App Engine flexible environment on\na Shared VPC network.\n\nSee [Provisioning Shared VPC](/vpc/docs/provisioning-shared-vpc) for more\ninformation about setting up a Shared VPC network.\n\nSetting up the App Engine flexible environment with Shared VPC\n--------------------------------------------------------------\n\nDeploying App Engine flexible environment instances on a\nShared VPC network involves three steps:\n\n1. [Create a firewall rule to allow App Engine flexible\n environment traffic on the Shared VPC network](#allowing-traffic)\n\n2. [Grant appropriate permissions to service accounts in the Shared VPC service project](#setting_up_permissions)\n\n3. [Configure your App Engine services to use the Shared VPC network](#configuring-deploying)\n\nIf you use the Google Cloud CLI, update to the latest\nversion before following this guide by running the command: \n\n gcloud components update\n\n### Allowing traffic to the Shared VPC network\n\nA Shared VPC Admin needs to create a firewall rule in the Shared VPC host\nproject in order to allow traffic to the App Engine flexible\nenvironment on the Shared VPC network. The firewall rule allows serving and\nhealth check traffic to flexible environment instances.\n\nThe firewall rule must have the following properties:\n\n- **Network**: The name of the Shared VPC network\n- **Direction of traffic**: Ingress\n- **Action on match**: Allow\n- **Targets**: Specified target tags\n- **Target tags** : `aef-instance`\n- **Source filter**: IP ranges\n- **Source IP ranges** : `35.191.0.0/16`, `130.211.0.0/22`\n- **Protocols and ports** : Specified protocols and ports\n - **tcp**: 8443, 10402\n\nA Shared VPC Admin can create the firewall rule using the Google Cloud console\nor the Google Cloud CLI: \n\n### Console\n\nTo create the firewall rule using the Google Cloud console:\n\n1. Go to the firewall rule creation page.\n\n [Create a firewall rule](https://console.cloud.google.com/networking/firewalls/add)\n2. In the **Name** and **Description** fields, provide a name and\n description for the firewall rule.\n\n3. Fill in the necessary properties as specified above.\n\n4. Click **Create**.\n\n### gcloud\n\nTo create the firewall rule using the Google Cloud CLI,\nrun the following command: \n\n```sh\ngcloud compute firewall-rules create NETWORK_NAME-flex-firewall \\\n--project HOST_PROJECT_ID \\\n--network NETWORK_NAME \\\n--allow tcp:10402,tcp:8443 \\\n--target-tags aef-instance \\\n--source-ranges 35.191.0.0/16,130.211.0.0/22 \\\n--description 'Allows traffic to App Engine flexible environment'\n```\n\nwhere:\n\n- \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e is the name of the Shared VPC network.\n- \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e is the Google Cloud project ID of the Shared VPC host project.\n\n### Setting up permissions\n\nA Shared VPC Admin must grant the following two service accounts\nthe [Compute Network User](/compute/docs/access/iam#compute.networkUser) role\nin order to allow a service project to deploy instances in the App Engine flexible environment\nto the network:\n\n- Google APIs service agent (\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@cloudservices.gserviceaccount.com`)\n- App Engine flexible environment service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@gae-api-prod.google.com.iam.gserviceaccount.com`)\n\n**Note:** App Engine creates the App Engine flexible environment service agent (`service-`\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@gae-api-prod.google.com.iam.gserviceaccount.com`) when you deploy your first app to the flexible environment. You can verify if the service agent exists in your project by following [these steps](/appengine/docs/flexible/service-agent#verifying_the_service_agent). \n\n### Console\n\nTo set up permissions using the Google Cloud console:\n\n1. Go to the IAM Settings page for the **service project**\n and take note of the **Project number**.\n\n [Go to IAM Settings](https://console.cloud.google.com/iam-admin/settings)\n2. Go to the IAM page for the **host project**.\n\n [Go to IAM](https://console.cloud.google.com/iam-admin/iam)\n3. Click **Add**.\n\n4. In the **New members** field, enter the following email addresses\n separated by a comma. Replace \u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e\n with the project number obtained in step 1.\n\n - \u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@cloudservices.gserviceaccount.com`\n - `service-`\u003cvar translate=\"no\"\u003ePROJECT_NUM\u003c/var\u003e`@gae-api-prod.google.com.iam.gserviceaccount.com`\n5. In the **Select a role** dropdown, select **Compute Engine** \\\u003e **Compute Network User**.\n\n6. Click **Save**.\n\n### gcloud\n\n1. Get the project number of the service project where the\n App Engine app is deployed. Run the following command,\n replacing \u003cvar translate=\"no\"\u003eSERVICE_PROJECT_ID\u003c/var\u003e with the\n project ID of the service project:\n\n ```sh\n export SERVICE_PROJECT_NUM=$(gcloud projects describe SERVICE_PROJECT_ID --format=\"value(projectNumber)\")\n ```\n2. Grant the service project's Google APIs Service Agent the\n `compute.networkUser` role in the host project:\n\n ```sh\n gcloud projects add-iam-policy-binding HOST_PROJECT_ID \\\n --member=serviceAccount:$SERVICE_PROJECT_NUM@cloudservices.gserviceaccount.com \\\n --role=roles/compute.networkUser\n ```\n\n where \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e is the\n Google Cloud project ID of the Shared VPC host project.\n3. Grant the service project's App Engine Flexible Environment\n Service Agent the `compute.networkUser` role in the host project:\n\n ```sh\n gcloud projects add-iam-policy-binding HOST_PROJECT_ID \\\n --member=serviceAccount:service-$SERVICE_PROJECT_NUM@gae-api-prod.google.com.iam.gserviceaccount.com \\\n --role=roles/compute.networkUser\n ```\n\n### Configuring and deploying your service\n\nAfter the firewall rule and proper permissions are set up, you can deploy\neither a new service or an existing App Engine flexible environment\nservice to the Shared VPC network.\n\n1. In the `app.yaml` file, use the\n [network settings](/appengine/docs/flexible/reference/app-yaml#network_settings)\n `name` field to specify the fully-qualified name of the Shared VPC network:\n\n ```\n network:\n name: projects/HOST_PROJECT_ID/global/networks/NETWORK_NAME\n ```\n\n where\n - \u003cvar translate=\"no\"\u003eHOST_PROJECT_ID\u003c/var\u003e is the Google Cloud project ID of the Shared VPC host project.\n - \u003cvar translate=\"no\"\u003eNETWORK_NAME\u003c/var\u003e is the name of the Shared VPC network.\n\n To configure the service to be part of a subnetwork named\n \u003cvar translate=\"no\"\u003eSUBNETWORK_NAME\u003c/var\u003e, also set the `subnetwork_name`\n field: \n\n ```\n network:\n name: projects/HOST_PROJECT_ID/global/networks/NETWORK_NAME\n subnetwork_name: SUBNETWORK_NAME\n ```\n2. Deploy the service:\n\n ```\n gcloud app deploy\n ```\n\n \u003cbr /\u003e\n\nVerifying your configuration\n----------------------------\n\nTo verify that your App Engine flexible environment\nservice is running on the Shared VPC network, view the version\nconfiguration on the App Engine versions page in the\nGoogle Cloud console:\n\n1. Go to the App Engine Versions page.\n\n [Go to App Engine versions](https://console.cloud.google.com/appengine/versions)\n2. In the **Config** column on the right, click on **View** for\n the desired version.\n\n3. Verify that the network name in the configuration is the name of\n the Shared VPC network."]]