Search code examples
google-cloud-platformgoogle-cloud-memorystore

Can not connect MemoryStore from the VM


I have created a VM instance and MemoryStore instance in the same project but can not connect from the VM.

# telnet 192.168.1.4 6379
Trying 192.168.1.4...
telnet: connect to address 192.168.1.4: Connection timed out

The VPC to which the VM belongs is designated as an approved network of Redis, the IP of Redis is not duplicated, and VPC peering is also automatically created. Do I need to set up firewall rules etc in addition?

VM and Redis are in the same regioins.

$ gcloud compute instances list --filter=name='staging-gateway'
NAME             ZONE          MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP    STATUS
staging-gateway  asia-east1-a  f1-micro                   172.17.0.7   *.*.*.*  RUNNING

$ gcloud redis instances list --region asia-east1
INSTANCE_NAME             REGION      TIER         SIZE_GB  HOST         PORT  NETWORK             RESERVED_IP     STATUS  CREATE_TIME
staging-whiteboard-redis  asia-east1  STANDARD_HA  1        192.168.1.4  6379  staging-*-vpc  192.168.1.0/29  READY   2019-02-05T03:03:08

Solution

  • To be able to connect to your Memorystore instance, when you create the VPC network you need to either select automatic subnet creation or allocate a subset of one of the following IP ranges:

    - 10.0.0.0/8
    - 192.168.0.0/16
    

    The issue is the internal IP allocated to your VM instance (172.17.0.7) which is trying to connect to the Memorystore instance. When you create the VPC, you should not allocate a subset of the IP range 172.17.0.0/16 to your custom subnet. That range is reserved for an internal component as seen in Limited and unsupported networks for Memorystore:

    Compute Engine VM instances that have an internal IP address within the range 172.17.0.0/16 cannot access Cloud Memorystore for Redis instances, because that range is reserved for an internal component.