busybox测试dns问题

获取svc

[root@master01 ~]# kubectl get svc
NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)       AGE
kubernetes        ClusterIP      10.68.0.1       <none>          443/TCP     5d6h
nginx-service    ClusterIP      10.68.36.30   <none>          5000/TCP   45h


启动busybox容器,解析kubernetes域名

[root@master01 ~]# kubectl run --rm -it  mybox-test --image=busybox

/ # nslookup kubernetes
Server:         10.68.0.2
Address:        10.68.0.2:53

** server can't find kubernetes.default.svc.cluster.local.: NXDOMAIN

*** Can't find kubernetes.svc.cluster.local.: No answer
*** Can't find kubernetes.cluster.local.: No answer
*** Can't find kubernetes.default.svc.cluster.local.: No answer
*** Can't find kubernetes.svc.cluster.local.: No answer
*** Can't find kubernetes.cluster.local.: No answer

问题分析:

初步看可能是域名不存在或者是dns连接不上


换成dig 镜像试试

[root@master01 ~]#  kubectl run dig --rm -it --image=docker.io/azukiapp/dig /bin/sh

/ # nslookup kubernetes
Server:         10.68.0.2
Address:        10.68.0.2#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.68.0.1

问题解决居然是镜像的问题


CoreDNS

CoreDNS在Kubernetes1.11版本已经做为GA功能释放,成为Kubernetes默认的DNS服务替代了Ku be-DNS,目前是kubeadm、kube-up、minikube和kops安装 工具 的默认选项。


使用ConfigMap做为配置文件。这份配置文件,会默认使用宿主机的DNS服务器地址。

[root@master01 ~]# kubectl -n kube-system get configmap coredns -oyaml
apiVersion: v1
data:
   Corefile: |
     .:53 {
         errors
         health
         ready
         kubernetes cluster.local. in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
         }
         prometheus :9153
         forward . /etc/resolv.conf
         cache 30
         reload
         loadbalance
     }
kind: ConfigMap
metadata:
   annotations:
     kubectl.kubernetes.io/last-applied-configuration: |
       {"apiVersion":"v1","data":{"Corefile":".:53 {\n    errors\n    health\n    ready\n    kubernetes cluster.local. in-addr.arpa ip6.arpa {\n      pods insecure\n      fallthrough in-addr.arpa ip6.arpa\n    }\n    prometheus :9153\n    forward . /etc/resolv.conf\n    cache 30\n    reload\n    loadbalance\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"coredns","namespace":"kube-system"}}
   creationTimestamp: "2019-08-23T08:39:06Z"
   name: coredns
   namespace: kube-system
   resourceVersion: "618253"
   selfLink: /api/v1/namespaces/kube-system/configmaps/coredns
   uid: 0510fab2-7327-4c1c-8b0e-87daaa3ee1ba


名称|含义

---|---

errors|错误会被记录到标准输出

health|可以通过http://localhost:8080/health查看健康状况

prometheus|可以通过http://localhost:9153/metrics获取prometheus格式的监控数据

proxy|本地无法解析后,向上级地址进行查询,默认使用宿主机的 /etc/resolv.conf 配置

cache|缓存时间


检查COreDNS运行状况

[root@master01 ~]# kubectl -n kube-system get pods -o wide|grep coredns
NAME                                          READY   STATUS    RESTARTS            AGE    IP                NODE        NOMINATED NODE   READINESS GATES
coredns-797455887b-4n8b7                      1/1     Running   0          2d2h   10.16.0.3   51.0.1.13   <none>           <none>
coredns-797455887b-qdgk6                      1/1     Running   0          2d2h   10.16.0.2   51.0.1.13   <none>           <none>

检查部署

[root@master01 ~]# kubectl -n kube-system get deployments
NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
coredns                      2/2                  2                 2           2d2h

posted @   MKY-门可意  阅读(3041)  评论(1编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
历史上的今天:
2016-08-25 python 多进程操作
2016-08-25 python 什么是全局解释器锁GIL
点击右上角即可分享
微信分享提示