skip to Main Content

I’m wanting to setup a Google Cloud memorystore redis instance and connect to it through my google cloud functions. After following this guide https://thecloudfunction.com/blog/firebase-cloud-functions-and-redis/

The general steps as I understand are:

  1. Enable Serverless VPC Service and create a connector for my function to use.
  2. Enable redis and create a redis instance on the same IP address range.

The problem is if I create the connector first (step #1) then I get this error when trying to create a redis instance (step #2):

Server response: Invalid value for field 'resource.ipCidrRange': '10.92.0.0/28'. Invalid IPCidrRange: 10.92.0.0/28 conflicts with peer network in active peering 'redis-peer-863826821838'.

And if I try and flip the steps, create the redis instance first (step #2) and then create the connector (step #1) then I get this error when trying to create the connector:

connector is in a bad state manual deletion recommended

I assume this is a problem with some IP range conflict per the first error but looking at the VPC connections I don’t see a conflict anywhere:

enter image description here

As far as I understand none of these should conflict with my IP range of 10.92.0.0/28, right?

All of this is happening on us-central1

Wondering if anyone knows how to correctly setup a redis instance + connector and move past these errors or if anyone has any suggestions on where to look for this IP range conflict and how to solve for it.

Thanks!

2

Answers


  1. Chosen as BEST ANSWER

    Okay so finally got this to work. For anyone else struggling with this issue here is what I had to do:

    1. Create a redis instance, and instead of manually entering Instance IP address range. Skip the field and create it without one. This is will generate a redis instance that doesn't conflict with any other ranged. For example 10.51.123.233
    2. Now create the connector and set it to the ip range of the created redis instance. For example if your redis instance generated an IP of 10.51.123.233 then you need to set the connect IP range to 10.51.0.0/28

  2. IP Address will be ‘occupied’ by the service

    I was learning GCP functions & redis using the official guide. In summary…

    Is good to learn a bit about CIDR. I found this online tool helpful.

    • Essentially the /28 indicates how many of the 32-bits are ‘locked’ as the prefix. 28 leaves 4 wildcard bits which is 16 addresses

    Redis and connector addresses must not overlap. Like OP, I thought I was connecting the redis IP to the function but this is wrong. The IP address inside your VPC will be ‘occupied’ by the connector. Same for redis.

    I successfully created a connector instance by designating a custom subnet (created in advance with CIDR 10.1.0.0/28)

    gcloud compute networks vpc-access connectors create connector6 
    --region=us-central1 
    --subnet=connector-subnet 
    --machine-type f1-micro
    

    However, creating a subnet for the redis instance did not work. Instead, a ‘redis-peer-…’ VPC network peer was created and caused the ip conflict message in OP above.

    # BAD: Creating subnet 'redis-subnet' with CIDR 10.2.0.0/28
    gcloud redis instances create redis6 
    --region=us-central1 --redis-version=redis_5_0 
    --network=vpc1 --reserved-ip-range=10.2.0.0/28
    

    Designating a fresh IP range worked.

    gcloud redis instances create redis6 
    --region=us-central1 --redis-version=redis_5_0 
    --network=vpc1 --reserved-ip-range=10.3.0.0/28
    

    Finally, deploying the function again worked.

    gcloud functions deploy visitCount 
    --runtime nodejs10 
    --trigger-http 
    --region us-central1 
    --vpc-connector projects/fc-redis-tutorial/locations/us-central1/connectors/connector6 
    --set-env-vars REDISHOST=10.3.0.3,REDISPORT=6379
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search