このページでは、Cloud Run リソースのネットワーク オプションを構成するためのベスト プラクティスの概要を説明します。リソースを作成する前に、このページのすべてのセクションを確認して、Cloud Run でサポートされているネットワーキング オプションとその影響を理解することをおすすめします。
ダイレクト VPC 下り(外向き)を使用している場合は、サブネットに十分な IP アドレスがあることを確認してください。使用する IP アドレスの数は、ワークロードが実行するインスタンスの数によって異なるため、IP アドレスの使用状況をモニタリングすることをおすすめします。時間の経過に伴う IP 使用量がサブネットでサポートされている範囲内に収まるようにしてください。
IP アドレスの使用量を推定する手順は次のとおりです。
Google Cloud コンソールで、Cloud Monitoring の [Metrics Explorer] ページに移動します。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-06-12 UTC。"],[],[],null,["# Best practices for Cloud Run networking\n\nThis page outlines the best practices for configuring networking options for\nCloud Run resources. Before you create your resources, we recommend\nthat you review all the sections on this page to understand the networking\noptions that Cloud Run supports, as well as their implications. \n**Best practices**:\n[Monitor IP address usage](#monitor-ip-usage). \n[Use non-RFC 1918 IP addresses](#non-rfc-1918). \n[Use IPv4 and IPv6 (dual-stack) subnets](#dual-stack-subnets). \n[Use connection pooling and reuse connections](#connection-pooling). \n[Faster external throughput to the internet](#external-throughput). \n[Faster internal throughput to a Google API](#internal-vpc-throughput). \n\nMonitor IP address usage\n------------------------\n\nIf you're using Direct VPC egress, [make sure that you have enough IP addresses\nfor your subnet](/run/docs/configuring/vpc-direct-vpc#before_you_begin). The\nnumber of IP addresses you use depends on the number of instances\nthat your workloads run, so we recommend monitoring your IP address usage. Be\nsure that your IP usage over time stays within the bounds supported by the\nsubnet.\n\nTo estimate your IP address usage:\n\n1. In the Google Cloud console, go to the Cloud Monitoring Metrics explorer page:\n\n [Go to Cloud Monitoring Metrics explorer](https://console.cloud.google.com/monitoring/metrics-explorer)\n2. Look up the number of instances in your project by using\n the metric type [`run.googleapis.com/container/instance_count`](/monitoring/api/metrics_gcp_p_z#gcp-run).\n Cloud Monitoring lets you view this metric's value over time.\n\n3. Multiply the instance count metric's value by 2 to get an estimate of the\n number of IP addresses in use.\n\nIP address exhaustion strategies\n--------------------------------\n\nHaving a large number of Cloud Run workloads can cause IP exhaustion\nchallenges when using the RFC 1918 private IP address space with Direct VPC\negress. The following strategies can help you manage IP address exhaustion by\nusing alternative IP address ranges.\n\n### Use non-RFC 1918 IPv4 addresses\n\nAside from the RFC 1918 IPv4 address ranges, Cloud Run also supports\n[RFC 6598](https://datatracker.ietf.org/doc/html/rfc6598#section-7) and\n[Class E/RFC 5735](https://tools.ietf.org/html/rfc5735) ranges. All\nGoogle Cloud services and features work with these non-RFC 1918 ranges,\nincluding VPC networks, Cloud Load Balancing, and\nPrivate Service Connect.\n\nFor the best compatibility, we recommend starting with the RFC 6598\n(100.64.0.0/10) range. If you're already using this range elsewhere,\nconsider using Class E/RFC 5735 (240.0.0.0/4). Class E is a huge space with over\n268 million IP addresses available, so it'll support your growth for a long\ntime. However, Class E has some limitations. For example, it's not supported on\nWindows and on some on-premises hardware. Read about\n[leveraging Class E IPv4 Address space to mitigate IPv4 exhaustion issues in GKE](https://cloud.google.com/blog/products/containers-kubernetes/how-class-e-addresses-solve-for-ip-address-exhaustion-in-gke).\n\n### Use Cloud NAT or Private Service Connect\n\nIf your Cloud Run workload using a non-RFC 1918 range needs to\nreach an on-premises destination that accepts only RFC 1918, use one of the\nfollowing solutions:\n\n- Use [Hybrid NAT](/nat/docs/private-nat) to perform address translation and egress using a small RFC 1918 range.\n- Expose the on-premises service as a [Private Service Connect](/vpc/docs/configure-private-service-connect-producer) hybrid service.\n\n### Use IPv4 and IPv6 (dual-stack) subnets\n\nAlthough it won't reduce IPv4 exhaustion, moving your apps to [IPv6](/vpc/docs/ipv6-support)\nis a good first step. [Set up dual-stack resources](/run/docs/configuring/vpc-dual-stack-subnet)\nto avoid IPv4 exhaustion problems in the future.\n\nPort exhaustion reduction strategies\n------------------------------------\n\nThe following section describes strategies for reducing port exhaustion with\nCloud Run.\n\n### Use connection pooling and reuse connections\n\nWhen sending a large number of requests to a single destination IP address,\nuse connection pooling to maintain and reuse connections to the destination.\nHigh connection rates to a single IP address can exhaust outbound ports and\ncause connection refused errors.\n\nPerformance and throughput strategies\n-------------------------------------\n\nThis section covers scalable options for improving network performance and\nthroughput towards the internet and Google services.\n\n### Use Direct VPC egress for faster network egress throughput\n\nTo achieve faster throughput across network egress connections, use Direct VPC\negress to route traffic through your VPC network.\n\n#### Example 1: External traffic to the internet\n\nIf you're sending external traffic to the public internet, route all traffic\nthrough the VPC network by setting\n[`--vpc-egress=all-traffic`](/sdk/gcloud/reference/run/deploy#--vpc-egress).\nWith this approach, you must set up Cloud NAT to reach the public internet.\n\nTo enable Cloud Run to use a Cloud NAT gateway for\nPublic NAT or Private NAT, see\n[Cloud NAT Direct VPC egress interactions](/nat/docs/nat-product-interactions#interactions-direct-vpc).\n\n#### Example 2: Internal traffic to a Google API\n\nIf you're using Direct VPC egress to send traffic to a Google API, such as\nCloud Storage, choose one of the following options:\n\n- Specify [`private-ranges-only`](/sdk/gcloud/reference/run/deploy#--vpc-egress) (default) with [Private Google Access](/vpc/docs/configure-private-google-access):\n 1. Set the flag `--vpc-egress=private-ranges-only`.\n 2. Enable Private Google Access.\n 3. [Configure DNS for Private Google Access](/vpc/docs/configure-private-google-access#config-domain). Make sure your target domain (such as `storage.googleapis.com`) maps to one of the following internal IP address ranges:\n - `199.36.153.8/30`\n - `199.36.153.4/30`\n- Specify [`all-traffic`](/sdk/gcloud/reference/run/deploy#--vpc-egress) with [Private Google Access](/vpc/docs/configure-private-google-access):\n 1. Set the flag `--vpc-egress=all-traffic`.\n 2. Enable Private Google Access.\n\nUse the default MTU setting for Cloud Run\n-----------------------------------------\n\nDon't change the [maximum transmission unit (MTU)](/vpc/docs/mtu) setting of a\nVPC network when using it with Cloud Run. Use the\ndefault MTU of 1,460 bytes instead.\n\nWhat's next\n-----------\n\n- [Compare Direct VPC egress and VPC connectors.](/run/docs/configuring/connecting-vpc)\n- [Use tags for testing, traffic migration and rollbacks.](/run/docs/rollouts-rollbacks-traffic-migration#tags)"]]