大网数据广告活动
服务器运维问答

How to use custom DNS servers on Google Cloud Run?

· 52CE 我爱测

I have a Cloud Run fully managed service that connects to a shared VPC using a connector. This shared VPC is managed by another GCP project and another team, but I can deploy instances to this VPC. This VPC has custom DNS servers…

问题原文

原帖链接 · Alex Pravdin · CC BY-SA 4.0

I have a Cloud Run fully managed service that connects to a shared VPC using a connector. This shared VPC is managed by another GCP project and another team, but I can deploy instances to this VPC. This VPC has custom DNS servers that resolve that team's internal resources. Custom DNS servers are not propagated by DHCP to the VPC users. I have access to all internal resources by IP from the Cloud Run container, but can't access them by name without using custom DNS servers.

The issue is that I can not propagate these servers to the container without getting some errors.

I made the following entrypoint script in my container:

#!/usr/bin/env sh
set -e

{
  echo "nameserver 10.80.64.19";
  echo "nameserver 10.80.64.20";
  echo "nameserver 10.80.64.21";
} >> /etc/resolv.conf

exec "$@"

This leads to the following file contents on the running container:

nameserver 10.80.64.21
nameserver 10.80.64.20
nameserver 10.80.64.19
search google.internal.
nameserver 169.254.169.254

(Custom lines added after what my script writes)

Sometimes the last NS server is used and I get errors connecting shared VPC resources by name (like Failed to resolve 'some-name').

How to solve this issue? AFAIK, I need either to use only custom DNS servers or "merge" information from them and from the standard server 169.254.169.254. How should I do in this case? What are possible solutions?

已采纳解答

原帖链接 · Alex Pravdin · CC BY-SA 4.0

The solution options were suggested by Google support:

The issue with handling at the Cloud Run side is that we cannot overwrite the resolv.conf since the networking stuff is being setup by Docker. We have two options to do this:

  1. Outbound Forwarding Zone: https://cloud.google.com/dns/docs/zones#creating-forwarding-zones
  2. Outbound server policy: https://cloud.google.com/dns/docs/policies#create-out

By implementing a Forwarding zone, you instruct cloud DNS that requests for which domain names should go to a specific DNS server. Good option if you have not so many internal zones names served by custom DNS servers.

By implementing an outbound policy, you change the resolution order and you may force sending resolution requests to custom servers first. Once the request reaches the VPC connector, it should go to the metadata server and it should know how to use the outbound server policy.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-12-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。