minikube Pod 无法解析 Service 主机名
minikube Kubernetes kubectl 大约 1430 字现象
使用nslookup
查询Service
名称,无法找到对应主机的IP
,显示为NXDOMAIN
。
/ # nslookup myspringboot
Server: 10.96.0.10
Address: 10.96.0.10:53
** server can't find myspringboot.default.svc.cluster.local: NXDOMAIN
** server can't find myspringboot.svc.cluster.local: NXDOMAIN
** server can't find myspringboot.cluster.local: NXDOMAIN
** server can't find myspringboot.cluster.local: NXDOMAIN
** server can't find myspringboot.default.svc.cluster.local: NXDOMAIN
** server can't find myspringboot.svc.cluster.local: NXDOMAIN
尝试解决(无效)
修改 net bridge 策略
查看nf-call
相关参数
sudo modprobe br_netfilter
sudo sysctl -a | grep nf-call
输出
net.bridge.bridge-nf-call-arptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
修改
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
备注:因为minikube
的虚拟机默认是Buildroot
,没有curl
、包管理器等命令。默认的nf-call
值都已经被赋予了1
。
修改 coredns ConfigMap
备注:默认都已经配置正确
kubectl -n kube-system edit configmaps coredns -o yaml
解决方法
最终有效的解决办法是:重启coredns
的Pod
。
kubectl -n kube-system rollout restart deployment coredns
备注
minikube
启动时指定的虚拟网卡是否能访问网络,如果不能访问网络,则coredns
不能解析外部网络的域名(如:在Pod
中nslookup baidu.com
是无法查询到的。)
补充
有些JDK
镜像是slim
版本,没有curl
、nslookup
等命令,可以使用kubectl debug
命令来注入sidecar
容器来帮助排查。
busybox
、alpine
等容器没有curl
。如果需要curl
可以使用nginx-alpine
容器(镜像解压后大小23
MB左右)
kubectl debug myspringboot -it --image=nginx:1.21.6-alpine -- sh
参考
https://stackoverflow.com/questions/45805483/kubernetes-pods-cant-resolve-hostnames
阅读 648 · 发布于 2022-11-19
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Element UI DatePicker 时间跨度限制在同一个月内阅读 5398
-
OpenResty 使用 ngx.timer.at 完成异步日志记录阅读 5003
-
Git 命令之本地仓库上传至远程仓库阅读 1993
-
单例双重校验为什么还要加 volatile阅读 575
-
Chrome 打开开发者工具的几种方法阅读 2174
-
HTTP Content-Type 为 application/x-www-form-urlencoded 时注意事项阅读 2819
-
走进 Rust:所有权阅读 1925
-
AndroidStudio non-zero value 1 错误阅读 1229
-
软考-系统架构设计师:IPv6阅读 2352
-
JavaScript/PHP 判断是否为微信内置浏览器阅读 2922