Utilizzo dell'ambiente flessibile di App Engine su una rete VPC condivisa
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Nell'ambiente flessibile di App Engine, puoi specificare una rete su cui eseguire il deployment delle istanze del servizio. Questa pagina mostra come configurare il progetto in modo da utilizzare l'ambiente flessibile di App Engine su una rete VPC condiviso.
Se utilizzi Google Cloud CLI, esegui l'aggiornamento alla versione più recente prima di seguire questa guida eseguendo il comando:
gcloud components update
Consentire il traffico alla rete VPC condiviso
Un amministratore del VPC condiviso deve creare una regola del firewall nel progetto host VPC condiviso per consentire il traffico verso l'ambiente flessibile App Engine sulla rete VPC condivisa. La regola del firewall consente il servizio e il traffico di controllo di integrità alle istanze dell'ambiente flessibile.
La regola firewall deve avere le seguenti proprietà:
Rete: il nome della rete VPC condiviso
Direzione del traffico: In entrata
Azione in caso di corrispondenza: Consenti
Target: Tag di destinazione specificati
Tag di destinazione: aef-instance
Filtro di origine: intervalli IP
Intervalli IP di origine: 35.191.0.0/16, 130.211.0.0/22
Protocolli e porte: Protocolli e porte specificati
tcp: 8443, 10402
Un amministratore VPC condiviso può creare la regola firewall utilizzando la Google Cloud console
o Google Cloud CLI:
Console
Per creare la regola firewall utilizzando la Google Cloud console:
Vai alla pagina di creazione della regola firewall.
HOST_PROJECT_ID è l' Google Cloud ID progetto
del progetto host VPC condiviso.
Configurazione delle autorizzazioni
Un amministratore VPC condiviso deve concedere ai seguenti due service account il ruolo Utente di rete Compute per consentire a un progetto di servizio di eseguire il deployment di istanze nell'ambiente flessibile di App Engine sulla rete:
Agente di servizio API di Google
(PROJECT_NUM@cloudservices.gserviceaccount.com)
Agente di servizio dell'ambiente flessibile di App Engine
(service-PROJECT_NUM@gae-api-prod.google.com.iam.gserviceaccount.com)
Console
Per configurare le autorizzazioni utilizzando la Google Cloud console:
Vai alla pagina Impostazioni IAM del progetto di servizio
e prendi nota del numero del progetto.
Nel campo Nuovi membri, inserisci i seguenti indirizzi email
separati da una virgola. Sostituisci PROJECT_NUM con il numero del progetto ottenuto nel passaggio 1.
Nel menu a discesa Seleziona un ruolo, seleziona Compute Engine > Utente rete Compute.
Fai clic su Salva.
gcloud
Recupera il numero del progetto di servizio in cui è dipiegato
l'app App Engine. Esegui il comando seguente,
sostituendo SERVICE_PROJECT_ID con l'ID progetto del progetto di servizio:
Configurazione ed esecuzione del deployment del servizio
Dopo aver configurato la regola firewall e le autorizzazioni appropriate, puoi eseguire il deployment di un nuovo servizio o di un servizio di ambiente flessibile App Engine esistente nella rete VPC condiviso.
Nel file app.yaml, utilizza il campo network settingsname per specificare il nome completo della rete VPC condiviso:
Per verificare che il servizio dell'ambiente flessibile di App Engine sia in esecuzione sulla rete VPC condiviso, visualizza la configurazione della versione nella pagina delle versioni di App Engine nella console:Google Cloud
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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."]]