title: Timeout behind GCP Nat
body: <p>I seem to have a problem similar to <a href="https://stackoverflow.com/questions/58027907/significant-delay-when-accessing-internet-via-google-cloud-nat">this</a> question in that I get the following timeout when building a docker image using a gitlab runner on GCP</p>
  
  <pre><code>Put https://registry.gitlab.com/v2/[redacted-repo]: dial tcp 35.227.35.254:443: i/o timeout
  </code></pre>
  
  <p>At this moment my google cloud NAT gives the following log output:</p>
  
  <pre><code>{
     "insertId": "rh7b2jfleq0wx",
     "jsonPayload": {
       "allocation_status": "DROPPED",
       "endpoint": {
         "project_id": "gitlab-autoscale-runners",
         "vm_name": "runner-5dblbjek-auto-scale-runner-1589446683-0b220f90",
         "region": "europe-west4",
         "zone": "europe-west4-b"
       },
       "connection": {
         "protocol": 6,
         "src_port": 42446,
         "src_ip": "some-ip",
         "dest_ip": "some-ip",
         "dest_port": 443
       },
       "vpc": {
         "vpc_name": "default",
         "subnetwork_name": "default",
         "project_id": "gitlab-autoscale-runners"
       },
       "gateway_identifiers": {
         "gateway_name": "gitlab-runner-gateway",
         "router_name": "gitlab-runner-router",
         "region": "europe-west4"
       }
     },
     "resource": {
       "type": "nat_gateway",
       "labels": {
         "region": "europe-west4",
         "router_id": "7964886332834186727",
         "gateway_name": "gitlab-runner-gateway",
         "project_id": "gitlab-autoscale-runners"
       }
     },
     "timestamp": "2020-05-14T10:17:55.195614735Z",
     "labels": {
       "nat.googleapis.com/nat_ip": "",
       "nat.googleapis.com/instance_name": "runner-5dblbjek-auto-scale-runner-1589446683-0b220f90",
       "nat.googleapis.com/network_name": "default",
       "nat.googleapis.com/subnetwork_name": "default",
       "nat.googleapis.com/router_name": "gitlab-runner-router",
       "nat.googleapis.com/instance_zone": "europe-west4-b"
     },
     "logName": "projects/gitlab-autoscale-runners/logs/compute.googleapis.com%2Fnat_flows",
     "receiveTimestamp": "2020-05-14T10:18:00.422135520Z"
   }
  </code></pre>
  
  <p>The aforementioned questions seems to indicate a problem with overutilized NAT ports. I have confirmed this not to be a problem in our case by utilising the google cloud CLI, see below.</p>
  
  <pre><code>$ gcloud compute routers get-nat-mapping-info gitlab-runner-router
  ---
  instanceName: runner-5dblbjek-auto-scale-runner-1589446683-0b220f90
  interfaceNatMappings:
  - natIpPortRanges:
    - some-id:1024-1055
    numTotalDrainNatPorts: 0
    numTotalNatPorts: 32
    sourceAliasIpRange: ''
    sourceVirtualIp: some-ip
  - natIpPortRanges:
    - some-ip:32768-32799
    numTotalDrainNatPorts: 0
    numTotalNatPorts: 32
    sourceAliasIpRange: ''
    sourceVirtualIp: some-ip
  </code></pre>
  
  <p>I seem to only be using some 64 ports.</p>
  
  <p>The google cloud router advertises the following status:</p>
  
  <pre><code>kind: compute#routerStatusResponse
  result:
    natStatus:
    - autoAllocatedNatIps:
      - some-ip
      minExtraNatIpsNeeded: 0
      name: gitlab-runner-gateway
      numVmEndpointsWithNatMappings: 3
    network: https://www.googleapis.com/compute/v1/projects/gitlab-autoscale-runners/global/networks/default  
  </code></pre>
  
  <p>The same docker-images does build successfully when run locally or in a shared gitlab runner i.e. when not behind the NAT.</p>
  
  <p>How do I prevent the timeout when building this docker image behind the google cloud nat?</p>