k8s 出現(xiàn)異常unknownhostexception

生產(chǎn)環(huán)境,沒(méi)有進(jìn)行升級(jí)或修改配置,卻突然出現(xiàn)某些pod服務(wù)無(wú)法訪問(wèn)hdfs的情況。拋出異常 unknownHostException

最終解決方法:重啟 k8s coreDns


最終解決耗時(shí) 2day

如果參照chatGPT 3.5的解決方案,應(yīng)該能節(jié)省不好時(shí)間。

問(wèn):k8s 出現(xiàn)異常unknownhostexception,怎么解決

答:
K8s 出現(xiàn) UnknownHostException 異常通常是由于 DNS 解析失敗導(dǎo)致的。解決方法如下:

1.  檢查 DNS 配置是否正確,確保 DNS 服務(wù)器能夠正常解析域名。

2.  檢查 Pod 的 DNS 配置是否正確,可以通過(guò) kubectl describe pod 命令查看。

3.  檢查 Pod 是否能夠訪問(wèn) DNS 服務(wù)器,可以通過(guò)在 Pod 中執(zhí)行 nslookup 命令來(lái)測(cè)試。

4.  如果以上方法都無(wú)法解決問(wèn)題,可以嘗試在 Pod 中手動(dòng)添加 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, &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>

這個(gè) Pod 會(huì)在啟動(dòng)時(shí)向 /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)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容