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

And*_*rew 20 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
Run Code Online (Sandbox Code Playgroud)

我正在尝试访问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> 
Run Code Online (Sandbox Code Playgroud)

根据文档,正确的访问点是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.
Run Code Online (Sandbox Code Playgroud)

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

ubuntu@master:~$ curl -k https://localhost/ui
Unauthorized
Run Code Online (Sandbox Code Playgroud)

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

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

ubuntu@master:~$ kubectl config view
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []
Run Code Online (Sandbox Code Playgroud)

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

liv*_*ton 9

您需要在本地运行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

  • 我得到`F0212 08:37:08.165120 20582 proxy.go:153]听tcp 127.0.0.1:80:bind:权限被拒绝`运行您的命令。另外我在/ etc / kubernetes和主文件夹中都没有amin.conf (3认同)

ysj*_*ang 9

官方Wiki有点令人困惑,因此我在这里对其进行了重新排序:

如果使用推荐的 Yaml部署仪表板,则只能通过https访问仪表板,并且应生成证书,请参阅指南。然后,您可以kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'在“ http:// localhost:8001 / ui ” 上运行以访问仪表板。该页面需要使用令牌登录。要生成它,请参考此页面。您也可以添加NodePort到yaml并使用进行访问<nodeip>:<port>

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

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


Yan*_*ung 8

您可以参考该文档:

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

简单的方法是

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

更改.spec.typeNodePort


use*_*318 6

您可以通过点击主控制台上的仪表板的nodePort来进行访问

kubectl describe services kubernetes-dashboard --namespace=kube-system
NodePort:       <unset> 30042/TCP
Run Code Online (Sandbox Code Playgroud)

http:// MASTER:30042


小智 6

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

\n
sudo ssh  -i \xe2\x80\x9cMYAMOZONHOSTKEYPAIR.pem" -L 8001:127.0.0.1:8001 ubuntu@MYAMAZONHOST\n
Run Code Online (Sandbox Code Playgroud)\n

MYAMAZONHOST 是我运行 k3s 的地方。

\n

通过 SSH 执行以下操作:

\n
sudo k3s kubectl proxy\n
Run Code Online (Sandbox Code Playgroud)\n

然后使用浏览器打开 url\nhttp://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

\n

Kubernetes 仪表板已成功打开。

\n


小智 5


你有没有试过这个:

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 访问仪表板。