Skip to content

DNS Resolution 失败

错误信息

                lookup 失败: 否 such host
              

快速摘要

DNS cannot 查找 IP 地址 for given hostname, 通常 due 到 DNS misconfiguration or hostname 不 existing.

为什么发生

  • hostname 做不 exist or 是 misspelled

  • DNS 服务器是 unreachable or misconfigured

  • Kubernetes CoreDNS service 是不 运行 or 是 misconfigured

  • /etc/resolv.conf file 有不正确 DNS 服务器条目

最小示例

✗ 错误代码
# Application references a misspelled service name
DB_HOST=datbase.example.com  # typo: missing 'a'
✓ 修复代码
# Correct the hostname
DB_HOST=database.example.com

hostname 有 typo ('datbase' 相反的 '数据库'). DNS cannot resolve 它. fix corrects spelling.

如何诊断

  • 测试 DNS resolution: nslookup <host> or dig <host>

  • 检查 CoreDNS in Kubernetes: kubectl 获取 pods -n kube-系统 -l k8s-app=kube-dns

  • 验证 hostname 是正确 and service exists

  • 检查 resolv.conf: cat /etc/resolv.conf

如何修复

  • 正确 hostname in 你的配置

  • 重启 CoreDNS: kubectl rollout 重启部署/coredns -n kube-系统

  • Fix DNS 服务器配置 in resolv.conf

  • 添加 DNS 条目 for hostname 如果它 是自定义内部 name

如何预防

  • Use Kubernetes Service names for 内部 communication (它们有 构建-in DNS)

  • Monitor CoreDNS health and alert on failures

  • 验证 hostnames in 配置之前 deploying

相关资源

相关术语

← 返回语言