如何将通配符子域名与静态子域名一起用于 Google Cloud 服务?

如何将通配符子域名与静态子域名一起用于 Google Cloud 服务?

假设我们拥有该域名example.com。在 Google Cloud 中,我想实现以下设置。

api-a.example.com和提供两项 Cloud Run 服务api-b.example.com

App Engine 中运行着第三个后端服务api-c.example.com

有一个 dockerized Nginx 容器,其前端部署到 App Engine 上frontend-a.example.com。这是我们公司员工使用的内部应用程序的前端。

最后一项服务是另一个 dockerized Nginx。它应该在通配符子域中可用*.example.com。如果上述子域均不匹配,则请求应在此处着陆。我们提供 SaaS,每个客户都有自己的子域,例如client-1.example.com。这些子域是不确定且不断变化的,因此我们希望使用通配符。

没有子域名的域名example.com不被使用。

这可能吗?如果可能,怎么做?

答案1

这是可能的,您可以按照以下步骤实现:

  1. 创建托管区域:(本例中创建了私有区域,但创建公共区域的步骤相同)
gcloud dns managed-zones create private-domain \
    --description=private-domain-example \
    --dns-name=example.com \
    --visibility=private
  1. 创建单独的记录,包括指向您的 dockerized Nginx 服务的通配符:(请注意通配符记录名称中的尾随点)
gcloud dns record-sets transaction start \
   --zone=private-domain

gcloud dns record-sets transaction add 10.10.3.2 \
   --name=*.example.com. \
   --ttl=86400 \
   --type=A \
   --zone=private-domain

gcloud dns record-sets transaction add 10.10.1.2 \
   --name=api-a.example.com \
   --ttl=86400 \
   --type=A \
   --zone=private-domain

gcloud dns record-sets transaction add 10.10.1.3 \
   --name=api-b.example.com \
   --ttl=86400 \
   --type=A \
   --zone=private-domain

gcloud dns record-sets transaction add 10.10.2.2 \
   --name=api-c.example.com \
   --ttl=86400 \
   --type=A \
   --zone=private-domain

gcloud dns record-sets transaction add 10.10.2.3 \
   --name=frontend-a.example.com \
   --ttl=86400 \
   --type=A \
   --zone=private-domain

gcloud dns record-sets transaction execute \
   --zone=private-domain

使用此设置,任何未明确定义的 example.com 域的请求都将转到 Nginx 服务,即通配符记录。您可以在此文档中找到有关 Cloud DNS 的完整文档,包括如何管理记录1

注意:该场景是使用 GCP 中的 VM 实例重新创建的,因此记录中的 RR_DATA 字段中的 IP 地址用于为 App Engine 服务创建 DNS 记录;您需要遵循此操作指南2

相关内容