如何访问/公开群集外的kubernetes-dashboard服务?

时间:2016-10-05 02:07:05

标签: kubernetes

我有以下服务:

ubuntu@master:~$ kubectl get services --all-namespaces
NAMESPACE     NAME                   CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
default       kubernetes             100.64.0.1      <none>        443/TCP         48m
kube-system   kube-dns               100.64.0.10     <none>        53/UDP,53/TCP   47m
kube-system   kubernetes-dashboard   100.70.83.136   <nodes>       80/TCP          47m

我正在尝试访问kubernetes仪表板。以下响应似乎是合理的,考虑到curl不是浏览器。

ubuntu@master:~$ curl 100.70.83.136
 <!doctype html> <html ng-app="kubernetesDashboard"> <head> <meta charset="utf-8"> <title>Kubernetes Dashboard</title> <link rel="icon" type="image/png" href="assets/images/kubernetes-logo.png"> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="static/vendor.36bb79bb.css"> <link rel="stylesheet" href="static/app.d2318302.css"> </head> <body> <!--[if lt IE 10]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser.
      Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your
      experience.</p>
    <![endif]--> <kd-chrome layout="column" layout-fill> </kd-chrome> <script src="static/vendor.633c6c7a.js"></script> <script src="api/appConfig.json"></script> <script src="static/app.9ed974b1.js"></script> </body> </html> 

根据文档,正确的访问点是https://localhost/ui。所以,我正在尝试并收到一些令人担忧的结果。 是否有预期的响应?

ubuntu@master:~$ curl https://localhost/ui
curl: (60) server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

在没有证书验证的情况下尝试相同的操作。对于卷曲,它可能没问题。但是我在浏览器中也有相同的功能,它通过vagrant forwarded_port选项连接端口转发。

ubuntu@master:~$ curl -k https://localhost/ui
Unauthorized

我做错了什么?以及如何确保我可以访问用户界面?目前它以未经授权的方式响应。

仪表板的文档告诉密码在配置中:

ubuntu@master:~$ kubectl config view
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []

但似乎我什么都没有...... 这是预期的行为吗?如何使用UI进行授权?

7 个答案:

答案 0 :(得分:7)

您需要在本地运行kubectl代理才能访问kubernetes集群外的仪表板。这是因为身份验证机制。运行以下命令后,您将能够在浏览器的http://localhost/ui处查看信息中心。 admin.conf文件是kubernetes master上的文件/etc/kubernetes/admin.conf 您必须将该文件scp到要从中访问仪表板的计算机并将其传递给kubectl命令。

  

kubectl --kubeconfig =。/ admin.conf proxy -p 80

如果以下两个条件之一有效,则@ user2363318提及的nodePort方法将适用:

  1. 您的http客户端(浏览器或curl)可以发送身份验证令牌
  2. 您在kubernetes群集中的服务没有auth

答案 1 :(得分:5)

您可以通过点击主要

上的仪表板的nodePort来实现
kubectl describe services kubernetes-dashboard --namespace=kube-system
NodePort:       <unset> 30042/TCP

http://MASTER:30042

答案 2 :(得分:5)

官方Wiki有点混乱,所以我在这里重新排序:

如果您使用recommend yaml部署仪表板,则只能通过https访问仪表板,并且应生成证书,请参考guide 然后,您可以运行kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'来访问“ http://localhost:8001/ui”上的信息中心。该页面需要登录使用令牌,具体参考this page。您也可以将NodePort添加到您的Yaml中,并使用<nodeip>:<port>

对其进行访问

如果您使用http alternative方法进行部署,则只能通过nodeip:port 访问仪表板,请记住先将其添加到Yaml中! 部署后,您还应该为每个请求生成令牌并添加标头Authorization: Bearer <token>

我认为这可以帮助您和其他想要使用kube-dashboard的人

答案 3 :(得分:4)

您可以参考该文件:

https://github.com/kubernetes/dashboard/wiki/Accessing-Dashboard---1.7.X-and-above

简单的方法是

$ kubectl -n kube-system edit service kubernetes-dashboard

.spec.type更改为NodePort

答案 4 :(得分:1)


您是否尝试过:
kubectl port-forward -n kubernetes-dashboard service/kubernetes-dashboard 10443:443 --address 0.0.0.0
在您的情况下,命名空间不同,因此:
kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443 --address 0.0.0.0

现在,您应该可以通过端口10443访问仪表板。

答案 5 :(得分:0)

只需对以上响应进行一些澄清,

  
    

将类型:ClusterIP更改为类型:NodePort并保存文件。

         

控制面板已在端口31707(HTTPS)上公开。现在,您可以从浏览器访问它:https://master-ip:31707

  

注意:所提到的端口可能与您的情况有所不同,只需运行以下kubectl命令从主服务器获取端口即可。

  
    

kubectl -n kube-system获取服务kubernetes-dashboard

  

答案 6 :(得分:0)

在笔记本电脑上使用终端应用程序执行以下操作:

sudo ssh  -i “MYAMOZONHOSTKEYPAIR.pem" -L 8001:127.0.0.1:8001 ubuntu@MYAMAZONHOST

MYAMAZONHOST是我运行k3s的地方。

通过SSH执行以下操作:

sudo k3s kubectl proxy

然后使用浏览器打开网址 http:// localhost:8001 / api / v1 / namespaces / kubernetes-dashboard / services / https:kubernetes-dashboard:/ proxy /

Kubernetes仪表板成功打开。

相关问题