Kubernetes 内部DNS访问 Service

网友投稿 627 2022-10-18

Kubernetes 内部DNS访问 Service

Kubernetes 内部DNS访问 Service

在 Cluster 中,除了可以通过 Cluster IP 访问 Service,Kubernetes 还提供了更为方便的 DNS 访问。

[root@k8s-master ~]# kubectl get deployment -n kube-systemNAME READY UP-TO-DATE AVAILABLE AGEcoredns 1/1 1 1 25h

coredns 是一个 DNS 服务器。每当有新的 Service 被创建,coredns 会添加该 Service 的 DNS 记录。Cluster 中的 Pod 可以通过 ​​.​​ 访问 Service。

[root@k8s-master ~]# kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.0.0.1 443/TCP 25dnodeport-svc NodePort 10.0.0.171 3000:30090/TCP 28h

用 ​​nslookup​​​ 查看 ​​nodeport-svc​​的 DNS 的信息。

/ # nslookup nodeport-svc.defaultServer: 10.0.0.2Address 1: 10.0.0.2 kube-dns.kube-system.svc.cluster.localName: nodeport-svc.defaultAddress 1: 10.0.0.171 nodeport-svc.default.svc.cluster.local

比如可以用 ​​Service ​​# wget nodeport-svc.default:3000Connecting to nodeport-svc.default:3000 (10.0.0.171:3000)saving to 'index.html'index.html 100% |*********************************************************| 41 0:00:00 ETA'index.html' saved

如果要访问其他 namespace 中的 Service,就必须带上 namesapce 了。Kubernetes 集群内部可以通过 Cluster IP 和 DNS 访问 Service。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:本小区物业管理系统分成两种角色,分别是小区业主和小区物业管理员 采用Spring框架 数据库连接用的是JdbcTemplate
下一篇:Docker 网络 none模式
相关文章

 发表评论

暂时没有评论,来抢沙发吧~