k8s-codedns 域名解析
1、 CoreDNS 的大多数功能都是由插件来实现的,插件和服务本身都使用了 Caddy 提供的一些功能,所以项目本身也不是特别的复杂。
pod与pod之间调用,可以通过名字或者svc直接访问(ectd数据库获取记录)。pod 访问外网通过宿主机网卡。
参考:https://www.cnblogs.com/cndr/p/15911802.html:v
一、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [yyapp@PH-K8S-M01 ~]$ [yyapp@PH-K8S-M01 ~]$ sudo kubectl describe configmap coredns -n kube-system Name: coredns Namespace: kube-system Labels: <none> Annotations: <none> Data ==== Corefile: ---- .:53 { errors health kubernetes cluster.local in -addr.arpa ip6.arpa { pods insecure upstream fallthrough in -addr.arpa ip6.arpa } prometheus :9153 proxy . /etc/resolv.conf cache 30 reload } Events: <none> [yyapp@PH-K8S-M01 ~]$ |
2、coredns解析过程。
1、先解析/etc/hosts (pod启动时候,yaml可以配置hostname)
2、通过本机的 /etc/resolv.conf ,进行域名解析 (nameserver 10.96.0.10 代表的coderdns svc地址,然后找到coredns容器)
3、coredns容器主要通过etcd数据库查询pod 和svc 、statefu 等来进行解析
3、无法找到的通过宿主机网卡。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | bash-4.4$ cat /etc/hosts # Kubernetes-managed hosts file. 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet fe00::0 ip6-mcastprefix fe00::1 ip6-allnodes fe00::2 ip6-allrouters 10.244.4.167 yylending-testyylendingsit05-basic-67dbd98b9f-s8p7b # Entries added by HostAliases. 172.29.1.147 testplmssit01image.yylending.com 172.29.1.147 testwptsit01.yylending.com 172.29.1.147 testwptsit02.yylending.com 172.29.1.147 testwptsit03.yylending.com 172.29.1.147 testwptsit04.yylending.com 172.29.1.147 testwptsit05.yylending.com 172.29.1.147 testwptsit06.yylending.com 172.29.1.147 testwptdev01.yylending.com 172.29.1.147 testwptdev02.yylending.com 172.29.1.147 testlcrmuat.yylending.com 172.29.1.147 testlassit01.yylending.com 172.29.1.147 testlassit02.yylending.com 172.29.1.147 testlassit03.yylending.com 172.29.1.147 testlas30219.yylending.com 172.29.1.147 testlassit05.yylending.com 172.29.1.147 testlassit06.yylending.com 172.29.1.147 testlassit07.yylending.com 172.29.1.147 testlassit08.yylending.com 172.29.1.147 testtasksit05.yylending.com |
1 2 3 4 5 | yyapp@LAPP-V714 ~]$ sudo kubectl exec -it busybox /bin/sh / # / # cat /etc/resolv.conf nameserver 10.96.0.10 #这里为coredns的svc地址 search default .svc.cluster.local svc.cluster.local cluster.local #按照这个过程进行解析 如pod名字为conclient.<br>依次为:podname.search default .svc.cluster.local 等等最后才是宿主机options ndots:5 #域名的.不超过5,超过5直接进行解析。不要通过上面的search。如 nsloolup podname<br><br> |
如果pod 提示域名不能解析到问题。1、通过手工yanl加 hostname解析 2、检查cordednss是否正常 3、宿主机网络是否正常
良禽择木而栖 贤臣择主而侍
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)