首页/云/Kubernetes 速查/ndots 与 DNS 解析行为调优
本包目录(307 条)
kubectl 基础56 条工作负载36 条
网络与服务55 条
配置与存储54 条调度与资源52 条集群运维与排障54 条

ndots 与 DNS 解析行为调优

Pod 的 resolv.conf 默认 ndots:5:名称中点数少于 5 时先尝试各 search 域,再试原始名称;这会让外部域名解析多绕几圈,也会造成「外部域名解析慢」。

Kubernetes 速查云更新于 2026-10-12

查看与复现

查看与复现
kubectl exec -it web-x -- cat /etc/resolv.conf
# search prod.svc.cluster.local svc.cluster.local cluster.local
# options ndots:5
kubectl exec -it web-x -- cat /etc/resolv.conf | grep -c ndots

缓解手段

缓解手段
spec:
  dnsConfig:
    options:
      - name: ndots
        value: "2"
对外部域名多用 FQDN 写法(api.example.com. 结尾加点)可避免 search 域试探;调 ndots 要评估集群内短名解析习惯。

易错点

  • 调小 ndots 后依赖短名 + 多级 search 域的内部解析可能变慢或失败,改动前先统计应用写法
  • 性能问题定位用 tcpdump/CoreDNS 日志确认重试次数,不要凭感觉改配置

数据来源与参考

  • Kubernetes 官方文档 · DNS for Services and Pods(ndots)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌