Menggunakan lingkungan fleksibel App Engine di jaringan VPC Bersama
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dalam lingkungan fleksibel App Engine, Anda dapat menentukan jaringan untuk men-deploy instance layanan Anda. Halaman ini menunjukkan cara mengonfigurasi project Anda untuk menggunakan lingkungan fleksibel App Engine di jaringan VPC Bersama.
Lihat Menyediakan VPC Bersama untuk informasi selengkapnya tentang penyiapan jaringan VPC Bersama.
Menyiapkan lingkungan fleksibel App Engine dengan VPC Bersama
Men-deploy instance lingkungan fleksibel App Engine di jaringan VPC Bersama memerlukan tiga langkah:
Jika Anda menggunakan Google Cloud CLI, update ke versi terbaru sebelum mengikuti panduan ini dengan menjalankan perintah:
gcloud components update
Mengizinkan traffic ke jaringan VPC Bersama
Admin VPC Bersama perlu membuat aturan firewall di project host VPC Bersama untuk mengizinkan traffic ke lingkungan fleksibel App Engine di jaringan VPC Bersama. Aturan firewall memungkinkan penyaluran dan health check terhadap traffic ke instance lingkungan fleksibel.
Aturan firewall harus memiliki properti berikut:
Network: Nama jaringan VPC Bersama
Direction of traffic: Masuk
Action on match: Izinkan
Targets: Tag target yang ditentukan
Target tags: aef-instance
Source filter: Rentang IP
Source IP ranges: 35.191.0.0/16, 130.211.0.0/22
Protocols and ports: Protokol dan port yang ditentukan
tcp: 8443, 10402
Admin VPC Bersama dapat membuat aturan firewall menggunakan Google Cloud konsol
atau Google Cloud CLI:
Konsol
Untuk membuat aturan firewall menggunakan konsol Google Cloud :
HOST_PROJECT_ID adalah Google Cloud project ID
dari project host VPC Bersama.
Menyiapkan izin
Admin VPC Bersama harus memberi dua akun layanan berikut peran Compute Network User agar project layanan dapat men-deploy instance di lingkungan fleksibel App Engine ke jaringan:
Agen layanan Google API (PROJECT_NUM@cloudservices.gserviceaccount.com)
Agen layanan lingkungan fleksibel App Engine (service-PROJECT_NUM@gae-api-prod.google.com.iam.gserviceaccount.com)
Konsol
Untuk menyiapkan izin menggunakan konsol Google Cloud :
Buka halaman IAM Settings untuk service project dan catat Project number.
Pada dropdown Select a role, pilih Compute Engine > Compute Network User.
Klik Save.
gcloud
Dapatkan nomor project dari project layanan di mana aplikasi App Engine di-deploy. Jalankan perintah berikut, dengan mengganti SERVICE_PROJECT_ID dengan project ID dari project layanan:
Setelah aturan firewall dan izin yang tepat disiapkan, Anda dapat men-deploy layanan baru atau layanan lingkungan fleksibel App Engine yang sudah ada ke jaringan VPC Bersama.
Dalam file app.yaml, gunakan kolom namesetelan jaringan untuk menentukan nama yang sepenuhnya memenuhi syarat dari jaringan VPC Bersama:
Untuk memverifikasi bahwa layanan lingkungan fleksibel App Engine Anda berjalan di jaringan VPC Bersama, lihat konfigurasi versi pada halaman App Engine Versions di konsolGoogle Cloud :
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-11 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."]]