第一次尝试将 kubernetes 配置为 DNS 解析给定域,而不是使用 given-domain.namespace.svc.cluster.local
Configure kubernetes to DNS resolve the given domain as the first try, instead of using given-domain.namespace.svc.cluster.local
默认情况下,当我们从一个 Pod 向另一个 Pod 提出请求时,Kubernetes 会尝试将 .namespace.svc.cluster.local
附加到我们提供的域并尝试解析。
但在我们的例子中,我们已经在所有地方使用完全合格的 URL 来提出请求 (http://service-name.namespace.svc.cluster.local/api/...),但这里 Kubernetes 也会尝试解析 DNS service-name.namespace.svc.cluster.local.namespace.svc.cluster.local
并尝试其他域,最后它只会尝试实际给定的域。
问题:有没有办法将 Kubernetes 配置为在第一次尝试时使用给定域进行 DNS 解析?如果失败则可以尝试其他域
环境信息:
环境:AKS
Pod OS:Debian GNU v10(克星)
附加信息:
Pod 中 /etc/resolv.conf
的内容
search namespance.svc.cluster.local svc.cluster.local cluster.local reddog.microsoft.com
nameserver x.x.x.x
options ndots:5
Wireshark:
正如你所看到的,对于每一个成功的请求,在它之前有 4 个失败的请求。
降低 ndots
将解决问题
ndots: sets a threshold for the number of dots which must appear in a name before an initial absolute query will be made. The default for n is 1, meaning that if there are any dots in a name, the name will be tried first as an absolute name before any search list elements are appended to it.
试试这个:
spec:
containers:
- name: ...
image: ...
dnsConfig:
options:
- name: ndots
value: "1"
默认情况下,当我们从一个 Pod 向另一个 Pod 提出请求时,Kubernetes 会尝试将 .namespace.svc.cluster.local
附加到我们提供的域并尝试解析。
但在我们的例子中,我们已经在所有地方使用完全合格的 URL 来提出请求 (http://service-name.namespace.svc.cluster.local/api/...),但这里 Kubernetes 也会尝试解析 DNS service-name.namespace.svc.cluster.local.namespace.svc.cluster.local
并尝试其他域,最后它只会尝试实际给定的域。
问题:有没有办法将 Kubernetes 配置为在第一次尝试时使用给定域进行 DNS 解析?如果失败则可以尝试其他域
环境信息:
环境:AKS
Pod OS:Debian GNU v10(克星)
附加信息:
Pod 中 /etc/resolv.conf
的内容
search namespance.svc.cluster.local svc.cluster.local cluster.local reddog.microsoft.com
nameserver x.x.x.x
options ndots:5
Wireshark:
降低 ndots
将解决问题
ndots: sets a threshold for the number of dots which must appear in a name before an initial absolute query will be made. The default for n is 1, meaning that if there are any dots in a name, the name will be tried first as an absolute name before any search list elements are appended to it.
试试这个:
spec:
containers:
- name: ...
image: ...
dnsConfig:
options:
- name: ndots
value: "1"