Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

kubernetes-dashboard無法訪問 #38

Closed
liujunfei980 opened this issue Dec 25, 2018 · 6 comments
Closed

kubernetes-dashboard無法訪問 #38

liujunfei980 opened this issue Dec 25, 2018 · 6 comments
Labels
help wanted Extra attention is needed works as intended Not a bug or issue

Comments

@liujunfei980
Copy link

liujunfei980 commented Dec 25, 2018

我按照此方法成功部署了3masrer k8s集群,但dashboard無法訪問
1、查看 kubernetes-dashboard日誌信息如下:

# kubectl logs  kubernetes-dashboard-94b488ddb-tn9cg -n kube-system
2018/12/25 05:41:39 Metric client health check failed: the server could not find the requested resource (get services heapster). Retrying in 30 seconds.
2018/12/25 05:42:09 Metric client health check failed: the server could not find the requested resource (get services heapster). Retrying in 30 seconds.
2018/12/25 05:42:39 Metric client health check failed: the server could not find the requested resource (get services heapster). Retrying in 30 seconds.

2、查看Metric 日誌

# kubectl logs metrics-server-5bff75b59f-54t27 -n kube-system
Error from server (BadRequest): a container name must be specified for pod metrics-server-5bff75b59f-54t27, choose one of: [metrics-server metrics-server-nanny]
@lentil1016
Copy link
Owner

从你的kubernetes-dashboard-94b488ddb-tn9cg日志看来,dashboard已经启动成功并正常运行,无法访问另有原因。关于Metric报出的错误,请参考 #30 了解其原因

该问题可能是由于hosts文件配置错误造成的。请将在你的任意一个master机器上运行下面命令的结果贴出,注意将第三条命令中的IP替换为你的K8s机器中任意一台运行了traefik容器的机器的IP。

kubectl get ing -n kube-system
DASHBOARD_HOST=`kubectl get ing -n kube-system -o wide|grep dashboard|awk '{print $2}'`
curl 10.130.75.64 -H "Host: ${DASHBOARD_HOST}"

另外,请附上无法访问时报出的错误代码,如404,503等

@lentil1016 lentil1016 added the help wanted Extra attention is needed label Dec 25, 2018
@liujunfei980
Copy link
Author

liujunfei980 commented Dec 25, 2018

執行結果如下:

# kubectl get ing -n kube-system
NAME             HOSTS                ADDRESS   PORTS   AGE
dashboard        dashboard.multi.io             80      8h
traefik-web-ui   ingress.multi.io               80      111m
# kubectl get pods -n kube-system -o wide|grep traefik
traefik-ingress-controller-t4k8x  1/1 Running   0  115m    10.206.132.113   zz-k8s-master03
traefik-ingress-controller-2fndb  1/1 Running   0  115m    10.206.132.112   zz-k8s-master02
traefik-ingress-controller-tq6f4  1/1 Running   0  115m    10.206.132.111   zz-k8s-master01
# DASHBOARD_HOST=`kubectl get ing -n kube-system -o wide|grep dashboard|awk '{print $2}'`
     curl 10.206.132.111 -H "Host: ${DASHBOARD_HOST}"
     Gateway Timeout

另外:1、traefik的控制台(http://vip:8080/dashboard/)可以正常訪問
2、dashboard控制台訪問(https://vip/),返回404 page not found

@lentil1016
Copy link
Owner

lentil1016 commented Dec 25, 2018

curl 10.206.132.111 -H "Host: ${DASHBOARD_HOST}"

10.206.132.111是你的traefik的Pod IP,不是机器的IP....,

另外:1、traefik的控制台(http://vip:8080/dashboard/)可以正常訪問
2、dashboard控制台訪問(https://vip/),返回404 page not found

并且你访问的方法根本就不是通过ingress访问,ingress的用法类似HTTP反向代理,需要通过特定的hostname进行访问。请参考我文档中提供的方法。
建议查看本文档学习ingress的用法

不好意思,后来意识到traefik没有Pod IP。请尝试在某个master上运行

$ kubectl proxy --address=0.0.0.0 --accept-hosts='.*'

随后通过浏览器访问该master的8001端口的如下地址,如果访问成功,则问题在于ingress,否则问题在于dashboard容器。

http://${MASTER_IP}:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

@lentil1016 lentil1016 added the works as intended Not a bug or issue label Dec 25, 2018
@liujunfei980
Copy link
Author

注釋:我集群環境中master01~maser03 IP地址分別是10.206.132.111、10.206.132.112、10.206.132.113
1、在master01節點執行
$ kubectl proxy --address=0.0.0.0 --accept-hosts='.*'
2、通過瀏覽訪問http://10.206.132.111:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
返回結果:Error: 'dial tcp 10.244.4.7:8443: i/o timeout'
Trying to reach: 'https://10.244.4.7:8443/'

@liujunfei980
Copy link
Author

非常感謝,我已經可以正常訪問dashboad了,主要原因如下:
1、我創建dashboad pod時,被分配到了worker節點上,導致gateway timeout
2、通過ingress部署的pod,只能通過域名的方式訪問,我把ingress.multi.io dashboard.multi.io兩個域名寫入到本地電腦hosts文件后,可以通過瀏覽器正常訪問dashboad了。

@hxdnshx
Copy link
Contributor

hxdnshx commented Mar 20, 2019

追记:我也遇到了相似的问题,之后找到原因是由于docker 1.13后可能会使 iptables FORWARD chain的默认策略设置为DROP,使得traefik无法跨node访问到dashboard,执行以下语句即可进行连接:
iptables -P FORWARD ACCEPT

ref:https://github.com/opsnull/follow-me-install-kubernetes-cluster/blob/master/07-1.docker.md

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed works as intended Not a bug or issue
Projects
None yet
Development

No branches or pull requests

3 participants