如何使用ingress和minikiube访问kubernetes仪表板



我正在尝试遵循使用minikube和ingress公开k8s仪表板的教程。基本上,我有以下入口蓝图:

apiVersion: v1
items:
- apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{},"labels":{"name":"dashboard-ingress"},"name":"dashboard-ingress","namespace":"kubernetes-dashboard"},"spec":{"rules":[{"host":"dashboard.com","http":{"paths":[{"backend":{"service":{"name":"kubernetes-dashboard","port":{"number":80}}},"path":"/","pathType":"Prefix"}]}}]}}
creationTimestamp: "2023-01-11T12:41:25Z"
generation: 1
labels:
name: dashboard-ingress
name: dashboard-ingress
namespace: kubernetes-dashboard
resourceVersion: "213743"
uid: ffe793ff-b985-4560-84d3-981007f7f309
spec:
ingressClassName: nginx
rules:
- host: dashboard.com
http:
paths:
- backend:
service:
name: kubernetes-dashboard
port:
number: 80
path: /
pathType: Prefix
status:
loadBalancer:
ingress:
- ip: 192.168.49.2
kind: List
metadata:

在我的host文件中,我添加了以下行:

192.168.49.2 dashboard.com

这就是我的host文件的样子:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
127.0.0.1 dashboard.com
# End of section

当我旋转dashboard.com时,我得到以下输出:

*   Trying 127.0.0.1:80...
* connect to 127.0.0.1 port 80 failed: Connection refused
*   Trying 2606:4700:3032::6815:11fe:80...
* Connected to dashboard.com (2606:4700:3032::6815:11fe) port 80 (#0)
> GET / HTTP/1.1
> Host: dashboard.com
> User-Agent: curl/7.85.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 11 Jan 2023 17:37:17 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< Location: http://www.dashboard.com/
< CF-Cache-Status: DYNAMIC
< Report-To: {"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v3?s=Fk%2F5iFEfMkDw1N8ej6xCnOz%2FvdhxnAz2Dg0NS8MtwjhopPZnCvJdt%2Fb6GNLtpB%2BK2TAVf11%2BYjCn4GSVQCWWhJvGlB97DE%2Bltvfn4TOSdNl1pKx0ev8I%2F3ik9HqCdXktIaAmYVzNhPyBw0%2Ba"}],"group":"cf-nel","max_age":604800}
< NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< Server: cloudflare
< CF-RAY: 787f6b60ce8a01b6-GRU
< alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
< 
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.22.0</center>
</body>
</html>
* Connection #0 to host dashboard.com left intact

我可以通过运行minikube dashboard正常访问仪表板。

我是k8s的新手。如我所见,IP地址192.168.49.2是一个外部IP地址。将它添加到我的主机文件中不会有帮助,我想因为它无论如何都不起作用。(minikube隧道必须配置,我尝试了几次,但它不工作)

我用的是Mac M1。

我的docker版本是:20.10.21我的minikube版本是:1.28.0我的kubectl版本是:1.25.2

我错过了什么?

因此,我关闭了使用隧道的终端,并启动了一个新的终端。基本上,对于minikube,任何影响外部IP地址的新更改都必须启动一个新的隧道:minikube tunnel

最新更新