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

标签 kubernetes dns nslookup

我已经使用 Calico CNI 构建了新的 Kubernetes 集群 v1.20.1 单主节点和单节点。
我在默认命名空间中部署了 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>

 
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'
集群正在运行带有最新更新的 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
resolve.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
正在运行的 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
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
定义了服务
# 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
启用了日志记录,但没有看到流量进入 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
我可以 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
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
如果我在主节点上安排 POD,nslookup 工作 nmap 显示端口打开?
# 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
为什么工作节点上运行的 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

最佳答案

首先,根据文档 - 请注意 Calicokubeadm支持 Centos/RHEL 7+ .
在两个 Calicokubeadm文档我们可以看到他们只支持 RHEL7+ .
默认 RHEL8 用途 nftables而不是 iptables (我们仍然可以使用 iptables,但 上的“iptables”| RHEL8 实际上是在后台使用内核的 nft 框架 - 查看 "Running Iptables on RHEL 8" )。

9.2.1. nftables replaces iptables as the default network packet filtering framework


我相信nftables可能会导致此网络问题,因为我们可以在 nftables 上找到 adoption page :

Kubernetes does not support nftables yet.


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

考虑到这一点,我将提供一些可能对您有帮助的信息 RHEL8 .
我已经重现了您的问题并找到了适合我的解决方案。
  • 首先,我打开了 Calico 所需的端口- 可以找到这些端口
    here在“网络要求”下。
    解决方法:
  • 接下来我恢复了旧的iptables所有集群的后端
    节点,您可以通过设置 FirewallBackend 轻松做到这一点。在/etc/firewalld/firewalld.confiptables如上所述
    here .
  • 最后我重新启动 firewalld使新规则生效。

  • 我试过 nslookup来自 Pod在工作节点(kworker)上运行,它似乎工作正常。
    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:/#
    

    关于Kubernetes DNS lookg 在工作节点上不起作用 - 连接超时;无法访问任何服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65744565/

    相关文章:

    .net - DNS GetHostEntry - 如何指定 DNS 服务器? 。网

    bash - 如何在 bash 中使用 nslookup 来验证 DNS 是否配置正确?

    c# - nslookup 和 GetHostEntry 有什么区别?

    kubernetes - 当下游服务抛出 5xx(500、502、503、504)错误时,Istio 断路器不会在连续错误上打开电路

    kubernetes - 将流量从 Kubernetes pod 转发到本地服务器

    ios - 代号一中的 DNS 问题

    c# - 使用 C# 捕获 nslookup shell 输出

    kubernetes - 如何通过 yaml 将 secret 文件设置为 kubernetes secret ?

    使用 SecurityContext readOnlyRootFilesystem 时 Kubernetes 137 退出代码

    php - 使用 CloudFlare 和 OpenShift 以及 WordPress 应用程序的重定向循环