执行kubectl exec -it报错分析
现象执行kubectl -it exec podname /bin/bash进入容器时报错:Error from server: error dialing backend: dial tcp: lookup k8sslave04 on 10.233.0.2:53: no such host原因api_server是用kargo以static pod形式部署的,整个k8s集群部署好之后又
现象
执行kubectl -it exec podname /bin/bash进入容器时报错:
Error from server: error dialing backend: dial tcp: lookup k8sslave04 on 10.233.0.2:53: no such host
原因
api_server是用kargo以static pod形式部署的,整个k8s集群部署好之后又把某一节点加入集群,此时如果pod起在这台节点上,使用kubectl exec -it就会报上述错。是因为api_server容器的/etc/hosts里没有这台后加入节点的信息,这时会去kubedns配置的/etc/resolv.conf的内部dns服务器(10.233.0.2:53)上解析此主机名。当然解析不到。
在api_server的日志里也可以看到相关报错:
E1124 08:36:27.650273 1 status.go:62] apiserver received an error that is not an metav1.Status: error dialing backend: dial tcp: lookup k8sslave04 on 10.233.0.2:53: no such host
I1124 08:36:27.650583 1 wrap.go:75] POST /api/v1/namespaces/default/pods/my-nginx2-769133329-9pw04/exec?command=%2Fbin%2Fbash&container=my-nginx2&container=my-nginx2&stdin=true&stdout=true&tty=true: (310.402107ms) 500
...
logging error output: "{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\"error dialing backend: dial tcp: lookup k8sslave04 on 10.233.0.2:53: no such host\",\"code\":500}\n"
解决办法
1.修改主机的/etc/hosts,把那个机器加进去
2.修改api_server的manifest文件,把主机/etc/host映射进去
备注:目前修改api_server的manifest有个问题,修改后kubelet自动创建api_server有问题,需要重启一下kubelet(systemctl restart kubelet):https://github.com/kubernetes/kubernetes/issues/12803
更多推荐
所有评论(0)