Prepare and test your skills
Prepare and test your skills
Architecting Cloud NAT (opens in a new tab) solutions for secure outbound connectivity means designing managed egress so private workloads reach the internet without public addresses. Traffic flows from a private virtual machine (VM) or Kubernetes Pod endpoint to a Cloud NAT gateway, which translates the private source address to a selected outgoing address and forwards the traffic to the external network. Because private endpoints never appear directly on the internet, the gateway becomes a central point for controlling which workloads can egress and which identity they present externally. This design supports zero-trust and defense-in-depth by limiting egress to explicitly selected sources with predictable external identities.
Cloud NAT gateway scope and traffic flow define a project-scoped and zone-scoped control for external North-South traffic, not for internal East-West traffic. The gateway configuration selects its outgoing identity by specifying leaf subnets that contain the outgoing Internet Protocol (IP) addresses to use. The same configuration selects its allowed sources by specifying label selectors that match specific Pod or VM endpoints, and the subnets, endpoints, and outgoing traffic must all reside in the same zone and project as the gateway.
Egress through the gateway follows an ordered path:
leaf subnets.This order enforces least privilege because only endpoints matched by the gateway label selectors can obtain outbound translation, and all other private endpoints remain isolated from the internet.
Project default egress NAT versus Cloud NAT is a choice between a deprecated automatic model and the current gateway model in Google Distributed Cloud air-gapped deployments. Projects were created with a default egress configuration that allowed VM or Pod endpoints carrying the label egress.networking.gke.io/enabled:true to egress using an egress IP automatically assigned to the project. Cloud NAT is now the main Network Address Translation (NAT) solution, and workloads in standard clusters must use Cloud NAT.
The two implementations cannot be used together, so architecture must choose one egress model per endpoint:
| Option | How endpoints are selected | How outgoing address is selected |
|---|---|---|
| Project default egress NAT | Endpoints with label egress.networking.gke.io/enabled:true | Egress IP automatically assigned to the project |
| Cloud NAT | Pod or VM endpoints matched by label selectors in the gateway configuration | Outgoing IP addresses from leaf subnets specified in the gateway configuration |
A Pod or VM endpoint cannot be connected to a Cloud NAT gateway through label selectors while also carrying the egress.networking.gke.io/enabled:true label. Migration therefore requires removing the default-egress label from endpoints and assigning them to a Cloud NAT gateway in the same project and zone.
Controlling egress identity with subnets and label selectors means combining which outgoing addresses the gateway may use with which endpoints may use the gateway. The leaf subnets named in the gateway configuration define the pool of outgoing IP addresses, so external allowlists, logging, and compliance checks see a predictable, project-owned source. The label selectors named in the same gateway define the eligible Pod and VM endpoints, so different applications, teams, or sensitivity levels can be assigned to different gateways with different outgoing addresses. Because gateways have project and zonal scope, a gateway in one project and zone cannot translate traffic for subnets or endpoints in another project or zone, which enforces blast-radius boundaries and requires explicit per-project, per-zone egress design rather than shared internet paths.
Layering Cloud NAT with network security controls means surrounding outbound translation with Virtual Private Cloud (VPC) (opens in a new tab) controls that limit who needs egress at all. Private resources should keep only internal IP addresses and reach Google APIs and services through Private Service Connect or Private Google Access while remaining isolated from the public internet. Organizational policies further restrict which resources are allowed to use external IP addresses, and the stateful VPC firewall applies distributed rules to each VM.
The layered controls that combine with Cloud NAT include:
Exam tip: Use Secure Web Proxy when outbound traffic can be fetched over HTTP(S) and needs identity controls; otherwise use Cloud NAT for general internet egress from VMs without external IP addresses.
Integrating Cloud NAT (opens in a new tab) with broader network security and observability frameworks means combining managed translation with firewall, private-access, and monitoring controls. A Cloud Router holds the gateway configuration as the control plane, while Andromeda software in the Virtual Private Cloud (VPC) network performs source network address translation (SNAT) on outbound packets and destination network address translation (DNAT) on established inbound responses. Cloud NAT never allows unsolicited inbound connections and does not replace firewall, identity, or private-access controls.
How firewall rules govern Cloud NAT egress is that VPC firewall rules still govern traffic that uses Cloud NAT, so a private VM can reach the internet only when egress firewall rules allow it. A Cloud NAT configuration is tied to a VPC network and serves the subnets and IP ranges selected in its mapping, and it cannot select individual VMs. When a Cloud NAT gateway for Public NAT uses manual NAT IP address assignment, the gateway shares a fixed set of common external source IP addresses that a destination party can allowlist.
Outbound traffic moves through an ordered path where each stage depends on the previous one:
Private NAT performs the same outbound function for private-to-private traffic between VPC networks or between VPC and on-premises or other cloud networks, but the Cloud NAT gateway translates sources by using IP addresses from the Private NAT subnet range.
How Private Google Access bypasses Public NAT is that traffic sent to Google APIs and services is routed through Private Google Access even if the VM that initiates the connection uses Public NAT. Private Google Access is the path for private VPC subnets to reach Google APIs and services without external IP addresses, and it takes precedence over Public NAT for that traffic. Use Private Google Access with custom DNS zones to allow connectivity from private subnets to Google APIs, which lets nodes and Pods pull container images and call APIs without sending that traffic through NAT external addresses. This separation creates a clear trust boundary where internet egress flows through the Cloud NAT gateway and its external addresses, while Google API traffic stays on private paths controlled by Private Google Access.
Defense-in-depth controls around Google Kubernetes Engine (GKE) egress mean Cloud NAT provides address translation while other controls decide which workloads can send traffic and where that traffic can go. Traffic leaving Pods within a service mesh is directed through dedicated egress gateway proxies (opens in a new tab) running on dedicated nodes, and the egress gateways scale with a horizontal Pod autoscaler so replica count grows and shrinks with traffic. The Cloud NAT gateway must provide enough simultaneous connections for those egress gateways, so setting an appropriate minimum number of ports per VM avoids port exhaustion and connection-reuse delays, and adding egress gateway replicas reduces endpoint-independent mapping conflicts.
The surrounding controls divide by network layer and scope:
| Control | Enforcement layer | Scope that the control applies to |
|---|---|---|
| VPC firewall rules | Layer 4 transport | Connections to and from GKE nodes, selectable by service account or network tag and by node pool |
| Kubernetes network policies | Layer 4 transport | Pods, scoped to a namespace and further scoped to particular Pods |
| Authorization policies | Layer 7 application | Traffic between Pods in the mesh and traffic leaving the mesh |
Namespaces provide isolation and delegated administrative control, with a dedicated namespace for network administrators to deploy the egress gateway and configure routing to external hosts. Sidecar resources control the configuration scope of sidecar proxies in each workload Pod by defining which namespaces, Pods, and external services are visible to a workload. Workload Identity grants Google Cloud API permissions to specific workloads through Identity and Access Management (IAM) following least privilege without handling secrets.
Logging, monitoring, and alerting for anomalous outbound traffic combine Cloud Logging for connection detail with Cloud Monitoring and Network Analyzer for fleet health and anomaly detection. Logging is disabled by default and, when enabled, traces NAT connections and bandwidth for distinct purposes:
Cloud NAT exposes key gateway metrics to Cloud Monitoring automatically, where the metrics flow from the NAT gateway to Cloud Monitoring for custom dashboards, metric queries, and alerting policies. Alerts can watch for port exhaustion, dropped packets from insufficient NAT IP addresses, sudden growth in simultaneous connections, or outbound volume spikes that suggest data exfiltration or compromised update behavior. Network Analyzer automatically monitors the Cloud NAT configuration and publishes Cloud NAT insights, so the insight flows from Network Analyzer to the operator as a complement to manually built alerts.
Exam tip: Traffic to Google APIs uses Private Google Access even when Public NAT covers the subnet, so firewall and NAT logs for internet egress do not account for Google API traffic.
Configuring and optimizing NAT gateway parameters and routing means tuning how a distributed translation service assigns addresses and ports without exposing private subnets. Cloud NAT (opens in a new tab) is a distributed, software-defined service that provides source network address translation (SNAT) for outbound traffic from private Google Cloud resources and destination translation (DNAT) only for established inbound responses. A Cloud Router (opens in a new tab) holds the gateway configuration as the control plane, while Andromeda software on the physical hosts enforces the translation. A Public NAT gateway is bound to one Virtual Private Cloud (VPC) network in one region and serves only the subnet IP ranges selected in its mapping, so private VM instances, GKE nodes, and serverless endpoints in those ranges can reach the internet without external IP addresses.
Static and dynamic port allocation control how the Cloud NAT gateway divides its pool of NAT IP addresses and source ports among endpoints. Static port allocation is the default and reserves the same fixed number of ports for every VM that uses the gateway. Dynamic port allocation lets the gateway allocate ports to each VM based on actual usage, between a configured minimum and maximum, which improves utilization of a fixed IP pool and helps prevent port exhaustion. Dynamic port allocation works with either automatic or manual NAT IP address allocation.
The allocation modes compare as follows:
| Allocation mode | How ports are assigned | Port controls | Choose when |
|---|---|---|---|
| Static port allocation | Same fixed reservation for each VM | Minimum ports per VM, range 2 to 57344, default 64 | Workloads are predictable and need stable, uniform reservations |
| Dynamic port allocation | Gateway expands and shrinks each VM between minimum and maximum based on usage | Minimum ports per VM, default 32; maximum ports per VM, default 65536 | VM demand varies widely or NAT IP addresses are constrained and must be fully utilized |
With manual allocation, the operator must still reserve enough external addresses for expected load, because an undersized pool causes dropped packets and, for proxy-based load balancer endpoints, HTTP 5xx errors. For managed proxy load balancers serving regional internet network endpoint groups (NEGs), the recommended tuning is 2048 minimum ports and 4096 maximum ports per VM. For operating system update workloads, specify at least 160 as the minimum ports per instance to handle concurrent update processes.
Minimum and maximum ports per VM define the lower reservation and the upper growth limit for each endpoint behind a Cloud NAT gateway. In static mode only the minimum applies, so raising the minimum increases per-VM capacity but consumes the shared NAT IP and port pool faster. In dynamic mode the gateway starts each VM at the minimum and adds ports on demand up to the maximum, then reclaims idle ports for reuse by other VMs. Tuning is a tradeoff between compatibility and efficiency because a value that is too low causes port exhaustion, connection failures, and dropped packets during bursts, while a value that is too high wastes ports on idle VMs and reduces the number of VMs a fixed set of NAT IP addresses can serve. Monitor allocation failures with the nat_allocation_failed metric and add NAT IP addresses or adjust the minimum and maximum before exhaustion affects production traffic.
Endpoint-independent mapping (EIM) is a NAT behavior defined in RFC 5128 that reuses the same external NAT IP address and port for a private endpoint regardless of the internet destination it contacts. Public NAT also supports endpoint-dependent filtering, and EIM is disabled by default when a gateway is created. When EIM is enabled, outbound traffic from one internal source maps consistently, which helps protocols and applications that expect a stable external identity across multiple destinations. EIM has strict compatibility limits that affect security and design choices because a Cloud NAT gateway with EIM enabled cannot use dynamic port allocation and cannot use NAT rules for custom source matching. Choose EIM when application compatibility requires a consistent external mapping, and choose dynamic port allocation or NAT rules when efficient scaling or fine-grained source control matters more.
Gateway routing scope determines which private sources can use outbound NAT within the bound network and region. The gateway applies to the VPC network and region selected with its Cloud Router, and to the configured source ranges including primary and secondary ranges for IPv4, or internal and external ranges for IPv6 NAT64. A configuration cannot select individual VMs, so every eligible endpoint in the chosen subnets or ranges shares the gateway, and multiple gateways in the same region and VPC network must use unique subnets or unique ranges within a subnet.
Several parameter changes immediately disrupt established flows because the gateway releases IP addresses or resets port assignments:
To maintain security posture while tuning, keep logging intent explicit because NAT logging is disabled by default, retain egress firewall controls on private VMs, and use manual NAT IP addresses only when an external allowlist requires stable, known source addresses.
Exam tip: Endpoint-independent mapping cannot be enabled together with dynamic port allocation or NAT rules.
Project default egress NAT allows Virtual Machine (VM) or Pod endpoints carrying the label egress.networking.gke.io/enabled:true to egress using an egress IP automatically assigned to the project, while Cloud NAT selects Pod or VM endpoints matched by label selectors and uses outgoing IP addresses from leaf subnets specified in the gateway configuration. The two implementations cannot be used together, so an endpoint cannot be connected to a Cloud NAT gateway while also carrying the default-egress label and migration requires removing the label and assigning the endpoint to a gateway in the same project and zone.
Use Secure Web Proxy when outbound traffic can be fetched over HTTP(S) and needs identity controls and HTTP(S) inspection instead of raw address translation. Otherwise use Cloud NAT for general internet egress from VMs without external IP addresses.
Traffic sent to Google APIs and services is routed through Private Google Access even if the Virtual Machine (VM) that initiates the connection uses Public NAT, and Private Google Access takes precedence over Public NAT for that traffic. This lets private Virtual Private Cloud (VPC) subnets reach Google APIs and services without external IP addresses, while internet egress flows through the Cloud NAT gateway and its external addresses.
An enterprise is deploying internal workloads across multiple subnets in a Google Cloud VPC without public IP addresses. The organization must meet the following egress security and partner integration requirements:
10.10.1.0/24) must route outbound traffic to external payment gateways using a dedicated, reserved static external IP address (IP_ADDRESS_1) for IP whitelisting.10.10.2.0/24) must route outbound traffic to an external reporting endpoint using a separate reserved static external IP address (IP_ADDRESS_2).Which Cloud NAT configuration should the cloud security engineer implement?
Last updated