k8s 出现异常unknownhostexception

生产环境,没有进行升级或修改配置,却突然出现某些pod服务无法访问hdfs的情况。抛出异常 unknownHostException

最终解决方法:重启 k8s coreDns


最终解决耗时 2day

如果参照chatGPT 3.5的解决方案,应该能节省不好时间。

问:k8s 出现异常unknownhostexception,怎么解决

答:
K8s 出现 UnknownHostException 异常通常是由于 DNS 解析失败导致的。解决方法如下:

1.  检查 DNS 配置是否正确,确保 DNS 服务器能够正常解析域名。

2.  检查 Pod 的 DNS 配置是否正确,可以通过 kubectl describe pod 命令查看。

3.  检查 Pod 是否能够访问 DNS 服务器,可以通过在 Pod 中执行 nslookup 命令来测试。

4.  如果以上方法都无法解决问题,可以尝试在 Pod 中手动添加 DNS 解析规则,例如:

<pre style="--tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; font-family: ui-monospace, SFMono-Regular, &quot;SF Mono&quot;, Menlo, Consolas, &quot;Liberation Mono&quot;, monospace; font-size: 12px; margin-top: 0px; margin-bottom: 16px; overflow-wrap: normal; overflow: auto; line-height: 1.45; background-color: rgb(246, 248, 250); border-radius: 6px; color: rgba(0, 0, 0, 0.8); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">

`apiVersion: v1
kind: Pod
metadata:
  name: dns-test
spec:
  containers:
  - name: dns-test
    image: busybox
    command: ['sh', '-c', 'echo "nameserver 8.8.8.8" >> /etc/resolv.conf && sleep 3600']` 

</pre>

这个 Pod 会在启动时向 /etc/resolv.conf 文件中添加一条 DNS 解析规则,指定 DNS 服务器为 8.8.8.8。

关于 K8s 出现 UnknownHostException 异常的更多信息,可以参考以下链接:

*   [https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/](https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/)
*   [https://stackoverflow.com/questions/52846292/kubernetes-java-unknownhostexception](https://stackoverflow.com/questions/52846292/kubernetes-java-unknownhostexception)
*   [https://github.com/kubernetes/kubernetes/issues/28402](https://github.com/kubernetes/kubernetes/issues/28402)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容