1

I am deploying a Cloudfunction with VPC network as follows:

gcloud beta functions deploy my-function
      --trigger-http
      --region europe-west1
      --memory 128MB
      --runtime nodejs16
      --entry-point entrypoint
      --allow-unauthenticated
      # needed to access compute instances
      # https://console.cloud.google.com/networking/connectors/list
      --vpc-connector cloud-function-connector
      # vpc connector should be used only to access private network
      --egress-settings private-ranges-only

Now, if my Cloudfunction uses IP address of compute resources, I can easily access them. However when I use their hostnames, the DNS are not resolved which ends up with:

Error: getaddrinfo ENOTFOUND my-compute-resource

What do I need to do to be able to use DNS for my compute instances?

Vojtěch
  • 275
  • 3
  • 11
  • 1
    Which hostnames - public or private? **my-compute-resource** is a hostname. You must use the Fully Qualified Domain Name (FQDN). https://cloud.google.com/compute/docs/internal-dns#view_instance_dns_name – John Hanley Mar 31 '22 at 05:25
  • `my-compute-resource` is a name of the instance. From other instances I can easily ping directly `ping my-compute-instance`. Thanks to you I found out that I can use `my-compute-instance.c.my-project.internal` - I guess that is the best I can get? – Vojtěch Mar 31 '22 at 08:51
  • I sometimes use /etc/hosts and store hostnames and IP addresses. Then I can use any name I want (short or FQDN). – John Hanley Mar 31 '22 at 17:06
  • @ Vojtěch Have you tried as @JohnHanley suggested? If yes, Can you post the procedure which you have followed as an answer. – Ramesh kollisetty Apr 04 '22 at 09:10
  • Hi, I have just used `my-compute-instance.c.my-project.internal` instead of `my-compute-instance` and thats how it works. – Vojtěch Apr 04 '22 at 14:19
  • @Vojtěch please post your solution as an answer and accept it so that it would be helpful for other community members for reference. – Ramesh kollisetty Apr 08 '22 at 10:15
  • @JohnHanley if you post your comment as an answer, I will accept it. – Vojtěch Apr 08 '22 at 18:11

1 Answers1

1

To access a resource via a host name, you must use the Fully Qualified Domain Name (FQDN). Only using the host portion will fail.

A Compute Engine VM has the following FQDN format:

VM_NAME.ZONE.c.PROJECT_ID.internal

If you only specify the VM_NAME, for which ZONE and PROJECT_ID should the request resolve to? That answer also determines which internal DNS server should be queried for the answer.

To prevent that ambiguity, Google Cloud DNS requires FQDN.

Internal DNS names and Shared VPC

John Hanley
  • 4,287
  • 1
  • 9
  • 20