k8s service的DNS名稱解析之CoreDNS


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工作流程圖
    image

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服務


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM