從 VPC 網路中的 Cloudfunctions 解析 DNS

從 VPC 網路中的 Cloudfunctions 解析 DNS

我正在使用 VPC 網路部署 Cloudfunction,如下所示:

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

現在,如果我的 Cloudfunction 使用運算資源的 IP 位址,我可以輕鬆存取它們。但是,當我使用它們的主機名稱時,DNS 未解析,最終結果為:

Error: getaddrinfo ENOTFOUND my-compute-resource

我需要做什麼才能為我的計算實例使用 DNS?

答案1

若要透過主機名稱存取資源,您必須使用完全限定網域名稱 (FQDN)。僅使用主機部分將會失敗。

Compute Engine 虛擬機器具有以下 FQDN 格式:

VM_NAME.ZONE.c.PROJECT_ID.internal

如果僅指定 VM_NAME,請求應解析為哪個 ZONE 和 PROJECT_ID?該答案還確定應向哪個內部 DNS 伺服器查詢答案。

為了防止這種歧義,Google Cloud DNS 需要 FQDN。

內部 DNS 名稱和共用 VPC

相關內容