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

2024-02-16

我有以下服务:

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 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.

在没有证书验证的情况下尝试相同的操作。对于卷曲来说可能没问题。但我在浏览器中得到了相同的结果,即通过 vagrantforwarded_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 进行授权?


官方 wiki 有点混乱,所以我在这里订购:

如果您使用受到推崇的 https://github.com/kubernetes/dashboard/blob/master/aio/deploy/recommended/kubernetes-dashboard.yamlyaml 来部署仪表板,您应该只通过 https 访问您的仪表板,并且您应该生成您的证书,请参阅guide https://github.com/kubernetes/dashboard/wiki/Installation。 然后你就可以运行kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'访问“http://localhost:8001/ui”上的仪表板。该页面需要使用token登录。要生成它,请参阅这一页 https://github.com/kubernetes/dashboard/wiki/Creating-sample-user。您还可以添加NodePort到您的 yaml 并使用它访问它<nodeip>:<port>.

如果您使用http 替代方案 https://github.com/kubernetes/dashboard/blob/master/aio/deploy/alternative.yaml方法,你可以仅通过 nodeip:port 访问您的仪表板。记得先添加到yaml!! 部署后,您还应该生成您的令牌并添加标题Authorization: Bearer <token>对于每个请求.

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在集群外部访问/公开 kubernetes-dashboard 服务? 的相关文章

随机推荐