Kubernetes DNS lookg 在工作节点上不起作用 - 连接超时;无法访问任何服务器

sfg*_*ups 5 dns nslookup kubernetes

我已经v1.20.1使用 Calico CNI构建了新的 Kubernetes 集群单主节点和单节点。

busybox 在默认命名空间中部署了pod。

# kubectl get pods busybox -o wide
NAME      READY   STATUS    RESTARTS   AGE   IP             NODE        NOMINATED NODE   READINESS GATES
busybox   1/1     Running   0          12m   10.203.0.129   node02   <none>           <none>

 
Run Code Online (Sandbox Code Playgroud)

nslookup 不起作用

kubectl exec -ti busybox -- nslookup kubernetes.default
Server:    10.96.0.10
Address 1: 10.96.0.10

nslookup: can't resolve 'kubernetes.default'
Run Code Online (Sandbox Code Playgroud)

集群正在运行带有最新更新的 RHEL 8

遵循以下步骤:https : //kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

nslookup 命令无法访问名称服务器

# kubectl exec -i -t dnsutils -- nslookup kubernetes.default
;; connection timed out; no servers could be reached

command terminated with exit code 1
Run Code Online (Sandbox Code Playgroud)

解决.conf文件

# kubectl exec -ti dnsutils -- cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local 
nameserver 10.96.0.10
options ndots:5
Run Code Online (Sandbox Code Playgroud)

正在运行的 DNS pod

# kubectl get pods --namespace=kube-system -l k8s-app=kube-dns
NAME                      READY   STATUS    RESTARTS   AGE
coredns-74ff55c5b-472vx   1/1     Running   1          85m
coredns-74ff55c5b-c75bq   1/1     Running   1          85m
Run Code Online (Sandbox Code Playgroud)

DNS pod 日志

 kubectl logs --namespace=kube-system -l k8s-app=kube-dns
.:53
[INFO] plugin/reload: Running configuration MD5 = db32ca3650231d74073ff4cf814959a7
CoreDNS-1.7.0
linux/amd64, go1.14.4, f59c03d
.:53
[INFO] plugin/reload: Running configuration MD5 = db32ca3650231d74073ff4cf814959a7
CoreDNS-1.7.0
linux/amd64, go1.14.4, f59c03d
Run Code Online (Sandbox Code Playgroud)

服务已定义

# kubectl get svc --namespace=kube-system
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   86m

**I can see the endpoints of DNS pod**

# kubectl get endpoints kube-dns --namespace=kube-system
NAME       ENDPOINTS                                               AGE
kube-dns   10.203.0.5:53,10.203.0.6:53,10.203.0.5:53 + 3 more...   86m
Run Code Online (Sandbox Code Playgroud)

启用日志记录,但没有看到流量进入 DNS pod

# kubectl logs --namespace=kube-system -l k8s-app=kube-dns
.:53
[INFO] plugin/reload: Running configuration MD5 = db32ca3650231d74073ff4cf814959a7
CoreDNS-1.7.0
linux/amd64, go1.14.4, f59c03d
.:53
[INFO] plugin/reload: Running configuration MD5 = db32ca3650231d74073ff4cf814959a7
CoreDNS-1.7.0
linux/amd64, go1.14.4, f59c03d
Run Code Online (Sandbox Code Playgroud)

我可以 ping DNS POD

# kubectl exec -i -t dnsutils -- ping 10.203.0.5
PING 10.203.0.5 (10.203.0.5): 56 data bytes
64 bytes from 10.203.0.5: seq=0 ttl=62 time=6.024 ms
64 bytes from 10.203.0.5: seq=1 ttl=62 time=6.052 ms
64 bytes from 10.203.0.5: seq=2 ttl=62 time=6.175 ms
64 bytes from 10.203.0.5: seq=3 ttl=62 time=6.000 ms
^C
--- 10.203.0.5 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 6.000/6.062/6.175 ms
Run Code Online (Sandbox Code Playgroud)

nmap 显示端口已过滤

# ke netshoot-6f677d4fdf-5t5cb -- nmap 10.203.0.5
Starting Nmap 7.80 ( https://nmap.org ) at 2021-01-15 22:29 UTC
Nmap scan report for 10.203.0.5
Host is up (0.0060s latency).
Not shown: 997 closed ports
PORT     STATE    SERVICE
53/tcp   filtered domain
8080/tcp filtered http-proxy
8181/tcp filtered intermapper

Nmap done: 1 IP address (1 host up) scanned in 14.33 seconds
Run Code Online (Sandbox Code Playgroud)

如果我在主节点上安排 POD,nslookup 工作 nmap show port open?

# ke netshoot -- bash
bash-5.0# nslookup kubernetes.default
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.96.0.1

 nmap -p 53 10.96.0.10
Starting Nmap 7.80 ( https://nmap.org ) at 2021-01-15 22:46 UTC
Nmap scan report for kube-dns.kube-system.svc.cluster.local (10.96.0.10)
Host is up (0.000098s latency).

PORT   STATE SERVICE
53/tcp open  domain

Nmap done: 1 IP address (1 host up) scanned in 0.14 seconds
Run Code Online (Sandbox Code Playgroud)

为什么工作节点上运行的 POD 的 nslookup 不起作用?如何解决这个问题?

我重新构建了服务器两次,仍然是同样的问题。

谢谢

SR

更新添加 kubeadm 配置文件

# cat kubeadm-config.yaml
---
apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
nodeRegistration:
  criSocket: unix:///run/containerd/containerd.sock
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
  kubeletExtraArgs:
    cgroup-driver: "systemd"
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: stable
controlPlaneEndpoint: "master01:6443"
networking:
  dnsDomain: cluster.local
  podSubnet: 10.0.0.0/14
  serviceSubnet: 10.96.0.0/12
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs
Run Code Online (Sandbox Code Playgroud)

mat*_*t_j 8

首先,根据文档 - 请注意Calicokubeadm支持Centos/RHEL 7+
Calico文档中kubeadm我们可以看到它们仅支持RHEL7+

默认情况下,RHEL8使用nftables而不是iptables(我们仍然可以使用,但RHEL8iptables上的“iptables”实际上是在后台使用内核的 nft 框架 - 请参阅“在 RHEL 8 上运行 Iptables”)。

9.2.1. nftables 取代 iptables 成为默认网络包过滤框架

我相信这nftables可能会导致此网络问题,因为我们可以在 nftables采用页面上找到:

Kubernetes 尚不支持 nftables。

注意:目前我强烈建议您使用RHEL7而不是RHEL8


考虑到这一点,我将提供一些可能对您使用RHEL8有帮助的信息。
我重现了您的问题并找到了适合我的解决方案。

  • 首先,我打开了所需的端口- 这些端口可以“网络要求”下Calico找到 。作为解决方法:
  • iptables接下来,我在所有集群节点上恢复到旧的 后端,您可以通过 按照此处所述FirewallBackend 设置 来轻松执行此操作。/etc/firewalld/firewalld.confiptables
  • 最后我重新启动firewalld以使新规则生效。

我尝试在工作节点(kworker)上nslookup运行Pod,它似乎工作正常。

root@kmaster:~# kubectl get pod,svc -o wide
NAME      READY   STATUS    RESTARTS   AGE    IP           NODE      NOMINATED NODE   READINESS GATES
pod/web   1/1     Running   0          112s   10.99.32.1   kworker   <none>           <none>

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE     SELECTOR
service/kubernetes   ClusterIP   10.99.0.1    <none>        443/TCP   5m51s   <none>
root@kmaster:~# kubectl exec -it web -- bash
root@web:/# nslookup kubernetes.default
Server:         10.99.0.10
Address:        10.99.0.10#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.99.0.1

root@web:/#
Run Code Online (Sandbox Code Playgroud)