Search code examples
google-cloud-platformgoogle-compute-enginegoogle-cloud-runsubnetgoogle-vpc

Share VPC connector


I am following this article[1] to get a fixed IP address of my Cloud Run instance, but my project already uses cloud memorystore (Redis) which requires a VPC serveless connector that I already using.

This is my serveless connector for Redis

gcloud beta compute networks vpc-access connectors list --region us-central1
CONNECTOR_ID         REGION       NETWORK  IP_CIDR_RANGE  SUBNET  SUBNET_PROJECT  MACHINE_TYPE  MIN_INSTANCES  MAX_INSTANCES  STATE
serveless-connector  us-central1  default  10.8.0.0/28                            e2-micro      2              3              READY

And I deploy with the following command line

gcloud beta run deploy service --vpc-connector=serveless-connector...

But on the documents, it seems to be nescessary another VPC connector on Cloud Run, in order to get the outbound NAT.

Is there some way to get Redis with VPC connector AND a static IP address?

UPDATE

If I run

gcloud compute networks subnets create subnet \
--range=10.8.0.0/28 --network=default --region=us-central1 --project ${PROJECT_ID} 

I got the error:

 - Invalid IPCidrRange: 10.8.0.0/28 conflicts with existing subnetwork 'aet-uscentral1-serveless--connector-sbnt' in region 'us-central1'.

1 - https://cloud.google.com/run/docs/configuring/static-outbound-ip


Solution

  • Posting the correct solution as community wiki. I deleted the previous connector and created again using the tutorial and worked! Here my steps.

    ```shell
    gcloud compute networks subnets create subnet \
      --range=10.8.0.0/28 \
      --network=default \
      --region=us-central1 \
      --project=${PROJECT_ID} 
    ```
    
    ```shell
    gcloud compute networks vpc-access connectors create vpc-access-connector \
      --region=us-central1 \
      --subnet-project=${PROJECT_ID} \
      --subnet=subnet \
      --project=${PROJECT_ID}
    ```
    
    ```shell
    gcloud compute routers create router \
      --network=default \
      --region=us-central1 \
      --project=${PROJECT_ID}
    ```
    
    ```shell
    gcloud compute addresses create ipddr0 --region=us-central1 --project=${PROJECT_ID}
    ```
    
    ```shell
    gcloud compute routers nats create nat \
      --router=router \
      --region=us-central1 \
      --nat-custom-subnet-ip-ranges=subnet \
      --nat-external-ip-pool=ipddr0 \
      --project=${PROJECT_ID}
    ```