1. CoreDNS名称解析
-
CoreDNS:是一个DNS服务器,Kubernetes默认采用,以Pod部署在集群中,CoreDNS服务监视Kubernetes API,为每一个Service创建DNS记录用于域名解析。
-
CoreDNS YAML文件:https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns/coredns
-
ClusterIP A记录格式:
. .svc.cluster.local -
示例:my-svc.my-namespace.svc.cluster.local
-
CoreDNS工作流程图
2. 案例
-
查看service服务
[root@k8s-master service]# kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8d probe-demo ClusterIP 10.104.161.168 <none> 80/TCP 4d1h web NodePort 10.100.222.42 <none> 80:30009/TCP 19h
-
启动一个busybox服务进行测试
[root@k8s-master service]# kubectl run -it dns-test --image=busybox:1.28.4 -- /bin/sh If you don't see a command prompt, try pressing enter. / # nslookup web Server: 10.96.0.10 Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local Name: web Address 1: 10.100.222.42 web.default.svc.cluster.local
-
注释,使用名称解析需要先安装CoreDNS服务