生產(chǎn)環(huán)境唧垦,沒有進行升級或修改配置窗轩,卻突然出現(xiàn)某些pod服務(wù)無法訪問hdfs的情況嗅回。拋出異常 unknownHostException
最終解決方法:重啟 k8s coreDns
最終解決耗時 2day
如果參照chatGPT 3.5的解決方案汞贸,應(yīng)該能節(jié)省不好時間。
問:k8s 出現(xiàn)異常unknownhostexception五督,怎么解決
答:
K8s 出現(xiàn) UnknownHostException 異常通常是由于 DNS 解析失敗導(dǎo)致的。解決方法如下:
1. 檢查 DNS 配置是否正確瓶殃,確保 DNS 服務(wù)器能夠正常解析域名充包。
2. 檢查 Pod 的 DNS 配置是否正確,可以通過 kubectl describe pod 命令查看遥椿。
3. 檢查 Pod 是否能夠訪問 DNS 服務(wù)器基矮,可以通過在 Pod 中執(zhí)行 nslookup 命令來測試。
4. 如果以上方法都無法解決問題冠场,可以嘗試在 Pod 中手動添加 DNS 解析規(guī)則家浇,例如:
<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, "SF Mono", Menlo, Consolas, "Liberation Mono", 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 解析規(guī)則,指定 DNS 服務(wù)器為 8.8.8.8碴裙。
關(guān)于 K8s 出現(xiàn) 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)