gpt4 book ai didi

kubernetes - 无法从K8S Pod内部解析DNS

转载 作者:行者123 更新时间:2023-12-02 12:26:05 25 4
gpt4 key购买 nike

在dnsutils Pod中执行ping stackoverflow.com

/ # ping stackoverflow.com
ping: bad address 'stackoverflow.com'
从pod内部看, /etc/resolve.conf文件看起来不错
/ # cat /etc/resolv.conf 
nameserver 10.96.0.10
search weika.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
10.96.0.10是kube-dns服务ip:
[root@test3 k8s]# kubectl -n kube-system get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 75d
core dns
[root@test3 k8s]# kubectl -n kube-system get  pod -o wide | grep core
coredns-6557d7f7d6-5nkv7 1/1 Running 0 10d 10.244.0.14 test3.weikayuninternal.com <none> <none>
coredns-6557d7f7d6-gtrgc 1/1 Running 0 10d 10.244.0.13 test3.weikayuninternal.com <none> <none>
当我将nameserver ip更改为coredns ip时。解决DNS是可以的。
/ # cat /etc/resolv.conf 
nameserver 10.244.0.14
#nameserver 10.96.0.10
search weika.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
/ # ping stackoverflow.com
PING stackoverflow.com (151.101.65.69): 56 data bytes
64 bytes from 151.101.65.69: seq=0 ttl=49 time=100.497 ms
64 bytes from 151.101.65.69: seq=1 ttl=49 time=101.014 ms
64 bytes from 151.101.65.69: seq=2 ttl=49 time=100.462 ms
64 bytes from 151.101.65.69: seq=3 ttl=49 time=101.465 ms
64 bytes from 151.101.65.69: seq=4 ttl=49 time=100.318 ms
^C
--- stackoverflow.com ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 100.318/100.751/101.465 ms
/ #
为什么会这样呢?

最佳答案

您还没有提到kubernetes的安装方式。您应该使用以下命令重新启动coredns pod。

kubectl -n kube-system rollout restart deployment coredns

关于kubernetes - 无法从K8S Pod内部解析DNS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63111346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com