如何在 k8s 叢集的 kube-flannel-ds pod 中設定 /etc/resolv.conf?

如何在 k8s 叢集的 kube-flannel-ds pod 中設定 /etc/resolv.conf?

我正在運行一個 kubernetes 叢集(裸機;v1.23),其中有一個主節點和三個工作節點。我使用 flannel (v0.19.2) 作為 pod 網路。

在我的系統日誌中,我看到類似以下的錯誤:Nameserver limits were exceeded, some nameservers have been omitted, the applied nameserver line is: 46.38.252.230 46.38.225.230 2a03:4000:8000::fce6,其起源於kube-flannel-dsPod。在豆莢內部我看到:

$ cat /etc/resolv.conf

nameserver 46.38.252.230
nameserver 46.38.225.230
nameserver 2a03:4000:0:1::e1e6
search

由於超過三行,因此會出現錯誤訊息。但我不確定如何解決這個問題,因為我不知道這個conf檔案是如何產生的。

在創建 k8s 集群時我做了:kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/v0.19.2/Documentation/kube-flannel.yml >> pod_network_setup.txt


更新

工作節點在 ubuntu 22.04 機器上運作。

貓 /etc/resolv.conf

# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0 trust-ad
search .

解析狀態

Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub
Current DNS Server: 46.38.252.230
       DNS Servers: 46.38.252.230 46.38.225.230 2a03:4000:8000::fce6 2a03:4000:0:1::e1e6

Link 2 (eth0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 3 (docker0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

答案1

如果dnsPolicy設定為Default,Kubernetes Pod 將從其所在的工作節點繼承 DNS 配置。

根據您的工作 Linux 發行版和其他詳細信息,您可能會在以下位置找到該配置:

  • /etc/resolv.conf

  • /etc/dhcp/dhclient.conf

  • /etc/sysconfig/network-scripts/(Fedora、Centos 和 RHEL)

相關內容