nslookup 在 kubernetes 中同一節點上的 2 個 pod 中出現奇怪的行為

nslookup 在 kubernetes 中同一節點上的 2 個 pod 中出現奇怪的行為

我有 2 個容器在同一個命名空間中運行。

  • pod 的 in-pod dnsx翼不解析主機名,但會解析 FQDN
  • pod 的 in-pod dns實用程式妥善解決。
✗  kgpo  
NAME                         READY   STATUS    RESTARTS   AGE
deathstar-7848d6c4d5-g248j   1/1     Running   0          15m
deathstar-7848d6c4d5-qnsp8   1/1     Running   0          15m
tiefighter                   1/1     Running   0          15m
utils                        1/1     Running   0          11m
xwing                        1/1     Running   0          15m

➜ kgsvc         
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
deathstar    ClusterIP   172.20.41.112   <none>        80/TCP    15m
kubernetes   ClusterIP   172.20.0.1      <none>        443/TCP   46d

➜ k ice image               
PODNAME                     CONTAINER  PULL    IMAGE                          TAG
deathstar-7848d6c4d5-g248j  deathstar  Always  docker.io/cilium/starwars      -
deathstar-7848d6c4d5-qnsp8  deathstar  Always  docker.io/cilium/starwars      -
tiefighter                  spaceship  Always  docker.io/tgraf/netperf        -
utils                       utils      Always  saritasallc/network-multitool  -
xwing                       spaceship  Always  docker.io/tgraf/netperf        -

以下 Pod:

  • x翼 (docker.io/tgraf/netperf)
  • 實用程式 (saritasallc/network-multitool)

Pod 顯示相同的/etc/resolv.conf值,但它們的查詢行為不同nslookup

➜ kex xwing -- cat /etc/resolv.conf  
search default.svc.cluster.local svc.cluster.local cluster.local ec2.internal
nameserver 172.20.0.10
options ndots:5

➜ kex utils -- cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local ec2.internal
nameserver 172.20.0.10
options ndots:5

實用程式吊艙可以查詢服務名稱死星xwing吊艙不能。僅透過服務的 FQDN:

➜ kex utils -- nslookup deathstar  
Server:     172.20.0.10
Address:    172.20.0.10#53

Name:   deathstar.default.svc.cluster.local
Address: 172.20.41.112

➜ kex xwing -- nslookup deathstar
nslookup: can't resolve '(null)': Name does not resolve

➜ kex xwing -- nslookup deathstar.default.svc.cluster.local
nslookup: can't resolve '(null)': Name does not resolve
nslookup: can't resolve 'deathstar': Name does not resolve
command terminated with exit code 1

Name:      deathstar.default.svc.cluster.local
Address 1: 172.20.41.112 deathstar.default.svc.cluster.loca

兩個 pod 都在同一個 eks 節點上運行。

在 coredns 中啟用日誌後,我看到以下內容:

// kex utils -- nslookup deathstar (success)
[INFO] 10.120.133.213:45918 - 30670 "A IN deathstar.default.svc.cluster.local. udp 53 false 512" NOERROR qr,aa,rd 104 0.000298996s
[INFO] 10.120.133.213:45293 - 18650 "AAAA IN deathstar.default.svc.cluster.local. udp 53 false 512" NOERROR qr,aa,rd 146 0.000405998s

// kex xwing -- nslookup deathstar (failure)
[INFO] 10.120.134.84:32840 - 45185 "AAAA IN deathstar. udp 27 false 512" NXDOMAIN qr,rd,ra 102 0.003295317s
[INFO] 10.120.134.84:32840 - 44875 "A IN deathstar. udp 27 false 512" NXDOMAIN qr,rd,ra 102 0.003334905s

相關內容